Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Silverstripe 2.3.0-rc2 puts out too many tags?


Reply


4 Posts   1125 Views

Avatar
SilverRay

Community Member, 167 Posts

3 January 2009 at 1:43am

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.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

3 January 2009 at 4:06am

Edited: 03/01/2009 4:07am

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 %>

Avatar
SilverRay

Community Member, 167 Posts

3 January 2009 at 2:44pm

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

Avatar
SilverRay

Community Member, 167 Posts

4 January 2009 at 8:45pm

Edited: 04/01/2009 9:47pm

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