Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Silverstripe 2.3.0-rc2 puts out too many tags?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1047 Views
  • SilverRay
    Avatar
    Community Member
    167 Posts

    Silverstripe 2.3.0-rc2 puts out too many tags? Link to this post

    Hi,

    Weird problem. In my template it says:

    <ul id="mainnav">
    <% control Menu(1) %>
       <li class="$LinkingMode">
          <a href="$Link" title="Go to the &quot;{$MenuTitle}&quot; section">$MenuTitle</a>
             <ul>
             <% control Children %>
                <li><a href="$Link" title="Go to the &quot;{$MenuTitle}&quot; section">$MenuTitle</a></li>
             <% end_control %>
             </ul>
       </li>
    <% end_control %>
    </ul>

    You know, to see second level menus when you hover over the first level. Normally works (with some JS added as well for IE6). But Silverstripe 2.3.0-rc2 renders the code like this (according to source view in my browser, I edited for brevity):

    <ul id="mainnav"
       <li class="current">
          <a href="/cmstest/" title="Go to the &quot;Home&quot; section">Home</a>
             <ul>
             </ul>
       </li>
       <li class="link">
          <a href="/cmstest/new-page/" title="Go to the &quot;test one&quot; section">test one</a>
             <ul>
                <li><a href="/cmstest/new-page-6/" title="Go to the &quot;New Page&quot; section">New Page</a></li>
                <li><a href="/cmstest/new-page-7/" title="Go to the &quot;New Page&quot; section">New Page</a></li>
                <li><a href="/cmstest/new-page-8/" title="Go to the &quot;New Page&quot; section">New Page</a></li>
             </ul>
       </li>
       <li class="link">
          <a href="/cmstest/new-page-2/" title="Go to the &quot;test two&quot; section">test two</a>
             <ul>
             </ul>
       </li>
       <li class="link">
          <a href="/cmstest/new-page-3/" title="Go to the &quot;test three&quot; section">test three</a>
             <ul>
             </ul>
       </li>
       <li class="link">
          <a href="/cmstest/new-page-4/" title="Go to the &quot;test four&quot; section">test four</a>
             <ul>
             </ul>
       </li>
       <li class="link">
          <a href="/cmstest/new-page-5/" title="Go to the &quot;test five&quot; section">test five</a>
             <ul>
             </ul>
       </li>
    </ul>

    As you can see, it closes ul and li tags where it is not supposed to. What gives? File a bug?

    - Ray.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Silverstripe 2.3.0-rc2 puts out too many tags? Link to this post

    This is why it's good practice to evaluate a loop before beginning it. Use:

    <% if Children %>
    <ul>
    <% control Children %>
    <li><a href="$Link" title="Go to the "{$MenuTitle}" section">$MenuTitle</a></li>
    <% end_control %>
    </ul>
    <% end_if %>

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Silverstripe 2.3.0-rc2 puts out too many tags? Link to this post

    Ha, yes I will. I was still in development mode, so I did not put in the if blocks yet (lazy, I know). Thanks.

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Silverstripe 2.3.0-rc2 puts out too many tags? Link to this post

    Yup, works now. Duh.

    Another thing I didn't realize in advance, is that if you go to the second level menu, you want the second level to stay (I use a nested, folding out menu thingie). So, on the home page you see the first level nav, when you hover you see the second level nav, but if you click on a second level item and go to that page, how would I then have the second level menu visible at all times? Without making all kinds of separate templates that is. Hmm.

    Edit: nevermind, I figured it out. Now I have to make it work with IE6 as well...

    1047 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.