Hard Coding Auto Nav

Permalink
Hi Guys

Just getting to grips with Concrete. I'm trying to hard code the autonav block into a custom template - its the prelimonary stage to building a drop down nav. However, the code i'm using (taken from a how-to on this site) doesn't appear to be working so i'm hoping someone can point me in the right direction.

I've tried hard coding:

<?php
       $navBT = BlockType::getByHandle('autonav');
     $navBT->controller->displayPages = 'second_level';
     $navBT->controller->orderBy = 'display_asc';
     $navBT->controller->displaySubPages = 'all';
     $navBT->controller->displaySubPageLevels = 'all';
     $navBT->render('view');
      ?>


But this generates nothing and i don't know enough about concrete to figure out why in a timely fashion. When i use you the auto nav block on the same page (via the cms ) it generates fine. So can anyone see what;s up with the code?

Many thanks,

Jeb

 
Jebediah replied on at Permalink Reply
Ok got the nav working now - seems there was something going a bit dippy with recognising the sub pages.

So question 2 - how do you hard code to display subpages of a specific page - as can be done with the using the block in the cms?

Many thanks,

Jeb
Jebediah replied on at Permalink Reply
Sorted! Ignore this one
PassionForCreative replied on at Permalink Reply
PassionForCreative
I'm having this exact same problem. Can you post up your solution please?
mkly replied on at Permalink Reply
mkly
You use the Collection ID of the page you need
$my_nav->controller->displayPages = 'custom';
$my_nav->controller->displayPagesCID = 5;

Let me know if you need a way to get the page Collection ID.
Jebediah replied on at Permalink Reply
Hi Mate

This is what I used

<?php   
 $navBT = BlockType::getByHandle('autonav');
     $navBT->controller->displayPages = 'top';
     $navBT->controller->orderBy = 'display_asc';
     $navBT->controller->displaySubPages = 'relevant';
     $navBT->controller->displaySubPageLevels = 'enough_plus1';
     $navBT->render('view');
?>


This code very simply displays the top level nav and then displays the subpages of the current parent only. What are you trying to achieve?

Oh and if anyone else is confused as to where the attributes are look in: autonav > form_setup_html.php . That file has all the attributes for the autonav that u can use in hardcode. Just incase anyone else has the same confusion.

And another handy bit of code:

<?php
      $bt = BlockType::getByHandle('autonav');
      $bt->controller->cParentID = '80';
      $bt->controller->displayPages = 'current';
      $bt->controller->orderBy = 'display_asc';
      $bt->render('view');
      ?>


This snippet is really good if you are making a drop down menu and the parent pages are fixed. So you just copy that code into each hidden rollover div (or however you've setup your menu) and then change the CParentID to match the parent link. Found that quite handy

Hope this helps!

Jeb
Jebediah replied on at Permalink Reply
Oh and if you used that code but it's still not showing the subpages make sure the parent pages do actually have subpages by going into Dashboard > Site Map.

I went wrong (being new to concrete) and where i thought i was creating subpages i wasnt. Or rather i had created them but not published them. So they weren't showing through.

Let me know how u get on!
PassionForCreative replied on at Permalink Reply
PassionForCreative
Hi Jebediah,

I'm making a Dual Language site and my Tree looks like this:

Index
Home (Eng)
About (Eng)
Details (Eng)
Program Details (Eng)

Home (Wel)
About (Wel)
Details (Wel)
Program Details (Wel)

I want to only display the menu for the language I'm in. Do you know how to write the autonav to do so?

Steve
Jebediah replied on at Permalink Reply
Hi Stephen

I'm not on my main computer at the mo so can't test precisely what I'm saying here. But I think the simplest way to do this is to just have a bit of php logic i.e.:

<?php
// Get the page parent ID. Not sure if you have to instantiate this.
$pageID = $page ->getCollectionParentID();
// Have the parent IDs for Welsh and English sections hard coded cos // you'll already know these from making the page via the cms
$english = 80; //this is just an example. Replace with the real ID
$welsh = 81;    //this is just an example Replace with the real ID
if ($pageID == $english) 
{
   //You create a separate php file for english_nav and set it up
   // as described below under adapting menu code
   include("english_nav.php"); 
}
else if  ($pagetID == $welsh) 
{
   include("welsh_nav.php");



Adapting Menu Code

<?php
      $bt = BlockType::getByHandle('autonav');
     //CHANGE THE BELOW FOR WELSH or ENGLISH parent ID
      $bt->controller->cParentID = '80';  
      $bt->controller->displayPages = 'current';
      $bt->controller->orderBy = 'display_asc';
      $bt->render('view');
      ?>


So essentially you make two include files (one for welsh and one for english) and the only adaptation you make is to the line for cParentID which you set for whatever the ID is for the Welsh parent page or the English parent page. You don't actually have to make these separate files i just like to keep things tidy.

I think that should work but I'm just doing this off the top of my head.

Let me know if it helps at all or if you need anything explained in more detail.

Jebediah
PassionForCreative replied on at Permalink Reply
PassionForCreative
Hi Jebediah,

Thanks for taking the time to write this. I have come up with a solution based on something you wrote above.

What I've done is created a site tree and using the Page Redirect add-on have set up:

Index

ENG (redirected to Home Eng)
Home (Eng)

WEL (redirected to Home Wel)
Home (Wel)

The Internationalisation addon has a redirect to Default Language set up anyway so while not terribly elegant, this solution does work.

I've used your code and suggestions from above to hard code in an autonav that looks for second_level and this tree then only displays the relevant menu from below the Parent Language
Jebediah replied on at Permalink Reply
haha I'll reply sooner next time :)

To be honest I am a bit lazy and fall back on php rather than exploring the addons. Not used that addon so i guess i have learned something :D

Glad it's all working for you now.

Oh yeah i took a peek at your websites too - really nice mate :)
PassionForCreative replied on at Permalink Reply
PassionForCreative
Thanks, more to add too but so busy I haven't had a chance.

I'm a designer rather than a developer so whats a piece of cake for a developer to do with a bit of logic I need to rely on an add-on so I guess we all have our strengths.
Jebediah replied on at Permalink Reply
Well long as you've got a solution all is well. Doesn't matter how you got there :)

I really admire people who are natural's at design - it's always a bit of a slog for me with a lot of head scratching and self deprecation haha. Still enjoy the process tho.

Right I shall let you get on as you sound very busy. I was having an idle 20 mins whilst taking stock and then i spotted your post and i'm a sucker for finding a solution to something :)
ollijarvinen replied on at Permalink Reply 1 Attachment
**** EDIT: SOLVED!!!!! ******

Just got confused by two parameters (SubPageLevels and SubpageLevelsNum).

Now the code looks like this and everything is working great:

<?php 
$bt_main = BlockType::getByHandle('autonav'); 
$bt_main->controller->displayPages = 'custom';
$bt_main->controller->displayPagesCID = '133';
$bt_main->controller->orderBy = 'display_asc';
$bt_main->controller->displaySubPages = 'relevant';
$bt_main->controller->displaySubPageLevels = 'custom';
$bt_main->controller->displaySubPageLevelsNum = '3';
$bt_main->render('view');
?>



I'll leave the original post below.

**************

I have a problem with auto-nav related to this topic.

I'd like to hardcode my auto-nav into my template instead of using page type defaults.

The problem is that I cant get sub page levels to appaer the way I want to. Well, with auto-nav block I CAN get it workin perfectly, but... There must be something wrong with a code, I think?

This is my current code:

<?php
       $bt_main = BlockType::getByHandle('autonav');
       $bt_main->controller->displayPages = 'custom';
      $bt_main->controller->orderBy = 'display_asc';                  
   $bt_main->controller->displayPagesCID = '133';
   $bt_main->controller->displaySubPages = 'custom';
   $bt_nav->controller->displaySubPageLevels = '1';            
      $bt_main->render('view'); 
?>


I've tried basically every parameter I could think of.... no luck.

.JPG Image is attached with some explanations.