trouble catching current page

steelej's Avatar

steelej

04 May, 2012 12:41 PM

I wonder if you might take a look at at this. I've done this a number of times to for menus, getting the current attribute and applying a class to at menu heading. For some reason it's not working here. I've verified the class is in the css and working properly,

        #foreach ( $item in $items )
        #set ( $head = $item.getChild("heading").value )
        #set ( $link = $item.getChild("toplink").getChild("path").value )
        #set ( $url = $item.getChild("url").value )
        #set ( $subs = $item.getChild("sublist").getChildren("item"))


     #if ( $link != "/" )
            ## Use the Page Chooser over the external URL field
            #set ( $headlink = $link )
        #else
            ## Only use this if the Page Chooser is blank
            #set ( $headlink = $url )
        #end

     #if ($item.getAttribute("current").getValue() == "true")
        <li><a class="current" href="${headlink}">${head}</a></li>
        #else
        <li><a href="${headlink}">${head}</a></li>
        #end

end

  1. 2 Posted by steelej on 04 May, 2012 01:25 PM

    steelej's Avatar

    I see that I work on this more, I have troubles beyond the stated problem with the current attribute. This is a drop-down menu. I've attached the xml I'm working with, the script,and the html output I'm trying to reproduce. I think the problem is in my use of a count for numbering elements in the menus. I'm finding setting a a count then increasing it by count + 1, yields 0, 01, 011, 0111, etc. I believe the javascript behind the menu is looking for 1, 2, 3, 4, etc.

    Any help would be appreciate.

  2. Support Staff 3 Posted by Charlie Holder on 04 May, 2012 01:36 PM

    Charlie Holder's Avatar

    If the $count is your only problem, changing to an integer instead of string should fix that.

    #set ( $count = 1 )
    #foreach ( $item in $list )
        <div class="post${count}">
            ## some HTML
        </div>
        #set ( $count = $count + 1 )
    #end
    

    If you're using Cascade 6.10+, there is a built in counter on each for loop object that you can reference and you don't have to iterate the count yourself.

    #foreach ( $item in $list )
        <div class="post${foreach.count}">
            ## some HTML
        </div>
    #end
    

    New native loop stuff in 6.10+ because of the Velocity 1.7 upgrade:

    $foreach.count - 1 based
    $foreach.index - 0 based
    $foreach.hasNext - boolean
    
  3. 4 Posted by steelej on 04 May, 2012 01:50 PM

    steelej's Avatar

    The ${foreach.count} worked great thanks. Still working on the current page problem and some others.

  4. Support Staff 5 Posted by Charlie Holder on 04 May, 2012 01:53 PM

    Charlie Holder's Avatar

    Try just:

    $item.getAttribute("current")
    

    It's either there or it isn't. You don't have to test for the value. If you're more comfortable testing the value, have you tried:

    $item.getAttribute("current").value == "true"
    
  5. Support Staff 6 Posted by Charlie Holder on 04 May, 2012 01:55 PM

    Charlie Holder's Avatar

    Also, if it's me, I'm doing it like this and only managing 1 line of HTML:

    #if ( $item.getAttribute("current") )
        #set ( $curr = "current" )
    #else
        #set ( $curr = "" )
    #end
    <li><a class="${curr}" href="${headlink}">${head}</a></li>
    
  6. 7 Posted by steelej on 04 May, 2012 02:11 PM

    steelej's Avatar

    Charlie, Not all of these menu headings will have a sublist (dropdown). I'm trying to write an if condition to not print the sublist if there are no values. Suggestions?

  7. 8 Posted by steelej on 04 May, 2012 02:20 PM

    steelej's Avatar

    Charlie,
    This is cleaner, I agree. Still I'm coming out with class="" as though it's not recognizing the current page.
    ________________________________________
    From: Charlie Holder [[email blocked]]
    Sent: Friday, May 04, 2012 9:55 AM
    To: Steele, James
    Subject: Re: trouble catching current page [Velocity Formats]

  8. Support Staff 9 Posted by Charlie Holder on 04 May, 2012 03:16 PM

    Charlie Holder's Avatar

    I don't think your <menu> nodes will have the current='true' attribute ever. Looks like you're using a structured method for creating the navigation and including it through a chooser. Is that correct?

    You'll want to compare the calling-page/system-page/link with each menu/toplink/link as you loop through. That should do it.

  9. 10 Posted by steelej on 04 May, 2012 03:50 PM

    steelej's Avatar

    That worked well and quickly. Thanks.

    I'm having getting the javascript to execute may be the way I've set this up.
    I set up the drop-down menu as a data-defined block.
    In the page data-definition, I included a block-chooser.
    I've selected the drop-down block on the page.
    It shows up but the javascript does not execute.
    If I take the html produced by the format and paste it into the default region wysiwyg, it works but not where the block is placed on the page.

  10. Support Staff 11 Posted by Charlie Holder on 04 May, 2012 06:01 PM

    Charlie Holder's Avatar

    Is there a dev publish I can look at?

    Attach the js code needed and I can try to reproduce.

  11. 12 Posted by steelej on 04 May, 2012 06:17 PM

    steelej's Avatar

    Charlie,
    I was in error. This is a css menu, not javascript.

    You can see the index page with my script running at http://www.wit.edu/_temp/cpce/
    If you click any of the menu headings they're all linked to a cpce-page.html that has the working hard-coded script in it.

  12. Support Staff 13 Posted by Charlie Holder on 04 May, 2012 06:34 PM

    Charlie Holder's Avatar

    I do see a difference in the HTML between the pages.

    http://www.wit.edu/_temp/cpce looks like this in one place:

    <li><a href="index.html">Programs</a> 
    <ul class="sub2">
    <li class="p1"><a href="index.html">Associate and Bachelor Degree Programs</a></li>
    <li class="p2"><a href="index.html">Master Degree Programs</a></li>
    <li class="p3"><a href="index.html">Certificate Programs</a></li>
    <li class="p4"><a href="index.html">Workforce Training and Development</a></li>
    <li class="p5"><a href="index.html">Corporate Training</a></li>
    </ul>
    </li>
    

    And the working version on http://www.wit.edu/_temp/cpce/cpce-page.html:

    <li><a class="" href="programs/index.html">Programs</a></li>
    <ul class="sub2">
    <li class="p1"><a href="http://www.cnn.com">Associate and Bachelor Degree Programs</a></li>
    <li class="p2"><a href="http://www.cnn.com">Master Degree Programs</a></li>
    <li class="p3"><a href="http://www.cnn.com">Certificate Programs</a></li>
    <li class="p4"><a href="http://www.cnn.com">Workforce Training and Development</a></li>
    <li class="p5"><a href="http://www.cnn.com">Corporate Training</a></li>
    </ul>
    

    The difference is the Programs <li> is already closed before the sublist starts. In the non-working version, the <li> stays open and then closes AFTER the sublist.

  13. 14 Posted by steelej on 04 May, 2012 06:55 PM

    steelej's Avatar

    Charlie, it took some poking around to find the right place to put the but I got it. I really appreciate your help.

    Sincerely, thanks.

    Jim

  14. steelej closed this discussion on 04 May, 2012 06:55 PM.

Comments are currently closed for this discussion. You can start a new one.