Need way to print count variable when displaying menu

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.
Locked
Ryno

Need way to print count variable when displaying menu

Post by Ryno »

I need a way of assigning a count variable to a , everytime the menu goes one level down. I've tried mucking around with the smarty syntax but have had no luck.

Below is a code snippet of what I need to achieve (see how the value after 'xc' increments each time)

Code: Select all

<ul id="nav2xc">
    <li><a href="#" title="xx">Menu item</a></li>
    <li><a href="#" title="xx">Menu item</a></li>
    <li><a href="#" title="xx">Menu item</a> 
      <ul id="xc1" title="Menu 1">
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
      </ul>
    </li>
    <li><a href="#" title="xx">Menu item</a> 
      <ul id="xc2" title="Menu 2">
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
        <li><a href="#" title="xx">Sub menu item</a></li>
      </ul>
    </li>
  </ul>
Any help would be appreciated.

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

Re: Need way to print count variable when displaying menu

Post by tsw »

{$node->hierarchy|truncate:1:""}

of if you go over 10 you might need something like

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

Re: Need way to print count variable when displaying menu

Post by Ryno »

Hey tsw,

I thought the solution might be something along those lines, although I would need to provide a check to capture values over 10.

Your solution though only solves half of my problem. I am having dramas with the repeat block as follows:

Code: Select all

{repeat string="<ul id=\"xc\">" times=$node->depth-$node->prevdepth}
You can only insert a string for 'string' (funny that) and I don't think it's possible to put '{$node->hierarchy|truncate:1:""}' in there (I've really really tried).

Below is what would be cool, but it doesn't.

Code: Select all

{repeat string="<ul id=\"xc{$node->hierarchy|truncate:1:""}\">" times=$node->depth-$node->prevdepth}
I guess what I should also be asking is how to use the {repeat} block and can I use something else instead?

Ryno
Last edited by Ryno on Mon May 29, 2006 2:06 am, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Need way to print count variable when displaying menu

Post by Dr.CSS »

just curious... what you need the xc1 xc2 for... does it have to be 1, 2, 3, ...

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

Re: Need way to print count variable when displaying menu

Post by Ted »

Time to break out the goofy smarty syntax...

Code: Select all

{capture name=myul}<ul id="xc{$node->hierarchy|truncate:1:""}">{/capture}
{repeat string=$smarty.capture.myul times=$node->depth-$node->prevdepth}
Hope that helps
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Need way to print count variable when displaying menu

Post by tsw »

Mark: css class and id shouldnt start with a number
Ryno

Re: Need way to print count variable when displaying menu

Post by Ryno »

Wonderful, I feel like Smarty and I have made up for the time being.

I don't expect anyone to post to this as it's my bad and quite frankly, I'm stoked with the amount of help I've recieved but...

I realised the value I actually need is not dependant upon the hierarchy as such. I really just need a count variable that is incremented everytime we go down 1 level.

Code: Select all

{if $node->depth > $node->prevdepth}
So how best to do this count variable thing? I've got a solution but I thinkt it's cludgy, mainly cause I wrote it. Can anyone suggest a 'best practices' solution.?

Ryno
Ryno

Re: Need way to print count variable when displaying menu

Post by Ryno »

@Mark: It needs to be xc1, xc2, xc3 because it's a show/hide menu thing and that's how the script identifies menu's to be expanded and contracted.

Have a look at http://inspire.server101.com/js/xc/ for more info.

Ryno
Locked

Return to “CMSMS Core”