Hierarchy Manager: Getting the root for each node

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Hierarchy Manager: Getting the root for each node

Post by nils73 »

Hi there,

I am trying to change an image in the header by using a unique id on the body tag. Let's assume my structure looks like this:

  1. Home
  2. Services
  2.1. First
  2.2. Second
  3. Contact
  3.1. Address
  3.2. Form

Is it possible to assign if home is active and if either Services, First or Second are active and of course if Contact, Address or Form is active?

I thought about "abusing" MenuManger to achieve this, but I didn't get it right. Then I read about Hierarchy Manager which has been introduced in 0.12 but for this one I couldn't find any documentation. Any help would be highly appreciated.

Regards,
Nils
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: Hierarchy Manager: Getting the root for each node

Post by nils73 »

Actually I did abuse the MenuMager for this one ... here is how it works:

Code: Select all

{foreach from=$nodelist item=node}
{if $node->current == true}{$node->hierarchy|truncate:1:""}{/if}
{/foreach}
Just in case somebody needs it ...

Regards,
Nils
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Hierarchy Manager: Getting the root for each node

Post by tsw »

Great find nils.

It might be better to collect these into wiki. just have to think for a place for these (maybe in the tips and trics section)
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am

Re: Hierarchy Manager: Getting the root for each node

Post by Elijah Lofgren »

nils73 wrote: Actually I did abuse the MenuMager for this one ... here is how it works:

Code: Select all

{foreach from=$nodelist item=node}
{if $node->current == true}{$node->hierarchy|truncate:1:""}{/if}
{/foreach}
Thanks Nils! I had been wondering how to get just the first digit of $node->hierarchy, but I didn't know about truncate. Thanks for showing me.
tsw wrote: It might be better to collect these into wiki. just have to think for a place for these (maybe in the tips and trics section)
I've been adding mine to this page: http://wiki.cmsmadesimple.org/index.php ... nu_Manager
It would be cool it other people added theirs.  :)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Hierarchy Manager: Getting the root for each node

Post by Dr.CSS »

what does this render on page or HTML/view source?

  mark
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am

Re: Hierarchy Manager: Getting the root for each node

Post by Elijah Lofgren »

mark wrote: what does this render on page or HTML/view source?
It would render the first digit of $node->hierarchy. For example if you have the following layout:
nils73 wrote:   1. Home
  2. Services
  2.1. First
  2.2. Second
  3. Contact
  3.1. Address
  3.2. Form
and the current page is "Services", "First, or "Second" then a "2" would be outputted. If the current page is "Contact, Address, or Form" then a "3" would be outputted.

I'm guessing this is what it does based on the code. I haven't tried it.  ;)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: Hierarchy Manager: Getting the root for each node

Post by nils73 »

Elijah,

right you are. It just outputs the first char of the node-elemente by truncating the whole string to 1 --- so it would not be suitable for websites with long main-menus but then Jacob Nielsen says you should not use more than 7 ... so truncate should do the trick almost every time.

In my case I needed it to have a CSS signature attached to the body so that it is like this in CMSMS-templates:

Code: Select all

</__body id="cat{cms_module module='menumanager' template='getSection'}">
Which means I have created a template called "getSection" in MenuManager which then renders as follows:

1. Home
2. Services
2.1. First
2.2. Second
3. Contact
3.1. Address
3.2. Form

By using CSS you can then specify a lot of thing, such as a different header-image for each section for example by using

Code: Select all

#cat3 div.header { background: url(imageforsection3.jpg); }
which would then be a different image for all header-divs that have been assigned the CSS signature for cat3 (Contact, Address, Form). But I can think of many other cases where this turns out to be very handy ...

Regards,
Nils
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: Hierarchy Manager: Getting the root for each node

Post by Ted »

Untested, but this might help for situations where you do go over 10.

Code: Select all

{$node->hierarchy|truncate:2:""|strip:"."}
streever

Re: Hierarchy Manager: Getting the root for each node

Post by streever »

YES!!!!

this is basically
exactly
what i am looking for, except i need to give each main button it's own class

oh, please, someone, help :D
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Hierarchy Manager: Getting the root for each node

Post by Dr.CSS »

In menu manager the template you are using add class="a{node->id}" which should output class="a15" for home page, you need a letter in front of it a it doesn't like numbers only...
streever

Re: Hierarchy Manager: Getting the root for each node

Post by streever »

Hi Mark,

Thank you!!! Thank you!!!!

I was kind of thinking that, and just testing it... you saved me a lot of additional testing trying to figure out if it would work or not.
Post Reply

Return to “CMSMS Core”