how is possible to have the level in de navigation trees of the current page ?

Permalink
Hi,

I need to know the level of the curent page to change my attribute for a navigation in my template :

if my page in on the level 4 set to :
$bt_main->controller->displayPages = 'current';
If it's on level 3 set to
$bt_main->controller->displayPages = 'bellow';

i try to find the number of the level in Page::getCurrentPage() but i don't find.

Is it possible ?

Thank a lot

sebastienj
 
cgrauer replied on at Permalink Reply
cgrauer
This is what I did. Don't know if there are shorter ways to reach the goal...

// Get the level of the active page in the navigation (result in $page_level)
$parent_id =  $c->getCollectionParentID();
$page_level = 0;
while ( $parent_id > 0 ) {
   $page_level++;
   $collection = Page::getById($parent_id);
   $parent_id = $collection->getCollectionParentID();
}
sebastienj replied on at Permalink Reply
sebastienj
Thanks a lot for your speedy answert!
Just 4 minutes before yiour message i has build a not nice but working variable to know..
Your systeme is really better..

I create in the template of a autonav a global variable with count($selectedPathCIDs) to retrieve de level..
there..
//this will create an array of parent cIDs 
   $inspectC=$c;
   $selectedPathCIDs=array( $inspectC->getCollectionID() );
   $parentCIDnotZero=true;   
   while($parentCIDnotZero){
      $cParentID=$inspectC->cParentID;
      if(!intval($cParentID)){
         $parentCIDnotZero=false;
      }else{
         $selectedPathCIDs[]=$cParentID;
         $inspectC=Page::getById($cParentID);
      }
   }



So thank a lot !
orisinal replied on at Permalink Reply
orisinal
I think it's also good to take a look at customising blocks, instead of hacking templates.

I think you can copy for example
concrete/blocks/autonav/view.php
OR
concrete/blocks/autonav/templates/header_menu.php
to
your_concrete_root/blocks/autonav/templates/leveltemplate.php
and customise it just the way you want to.

Just remember to change the new template to autonav. This way you can use navigation with this same markup with whatever site or theme.
sebastienj replied on at Permalink Reply
sebastienj
:-)
Thanks for the information !
i'm already know well about block and template :-)
orisinal replied on at Permalink Reply
orisinal
Ehh...sorry. For some reason I assumed you were editing the template of your theme instead of autonav template. Or maybe you did, and it's ok, just wanted to say there are different ways.

Well, hopefully this made it more clear for some other guys instead of confusing :)
cgrauer replied on at Permalink Reply
cgrauer
You're right, it's important to reflect this question. But in this case I think the custom block template is the wrong place. The level refers to the collection, not to the (autonav)block!

What if you want to display or not a autonav block depending on the page's level? You need the level before calling the block. What if you don't use autonav at all but just want to display other things based on the level?

The level should rather be a property of the collection class. But this would mean to hack the core...
orisinal replied on at Permalink Reply
orisinal
Yes, I agree that it would be nice to get the level straight from the collection object. I'm just not sure if it's good design, that you start to show different blocks based on level, instead of using custom page types, for example. What happens if you or someone else re-organize your site structure and levels are changed? It becomes easily hard to maintain.

I think in this case sebastienj just wants to set the displayPages value for the navigation, depending on the level of current page. Sorry, but I didn't really understand why this shouldn't be done in custom autonav template.

I've been using Concrete5 1 month and 1 day now, so I can't say I'm speaking only truth here :)
cgrauer replied on at Permalink Reply
cgrauer
Page-Types? What happens if you or someone else re-organize your site structure and levels are changed? (first-level pages at once will have the third-level page type etc...!) It becomes easily hard to maintain. ;-)
And what happens if you or someone else uses a wrong page type? I don't like to have too much page types.
If it's really the level and no other criteria that decides about what content to show on a certain page, it definitively is better design to refer to the level and not to use page types. It also makes it easier for the editor to manage the site because he hasn't to worry about what page type to use for what page. So as always the quality of "design" depends on what you want to do with it.

That's only my opinion. I like to create sites that do everything automatically, if it's not absolutely neccessary to make it manually. I think this is somehow the goal of CMS, isn't it? Defaults over configuration...

sebastienj's problem is special though, as it belongs only to autonav. It really could be done in the custom template.
orisinal replied on at Permalink Reply
orisinal
I didn't mean I'd tie the page type to the level, that would be a nightmare :) This becomes bit off-topic, and maybe we're thinking these examples differently, while having same logic and goal.

(Still I have to continue. I hope you dont take this as proving I'm right and you're wrong. "There are many ways to get what you want").

I definately wouldn't make own pagetype for this, as those pages probably don't have unique data (or in some cases layout) compared to others. However, if I had a site of cinema company where all the movies happens to be at level 4, where I should show my neat block showing the shows, I'd make own page type for movies for sure, without any look at the level. If there were page types as "Movie, Cinema, Event, Main page", it should be pretty clear for editor guys which page type to choose, but it's possible to use advanced permissions and allow people in Editor group to use only specific pagetype in specific part of site. Now if after two years this company changes it's look and you should convert their new beautiful theme with some re-organising, I'd go with page types and properly customised blocks instead of hacked theme.

Would be nice to hear from sebastienj the real problem behind this question. Why did you end up with this solution? Maybe there are users who will have this same situation and maybe they'll find this thread.