5 Replies Latest reply on Mar 2, 2004 12:54 AM by thepriz

    nested templates

      How deep can the nesting go?

      <!-- BEGIN main -->
      ...
      <!-- BEGIN downloadListLoop -->
      ...
      <!-- BEGIN displayNewToDay -->
       <img src="modules/downloads/images/new_1.gif" alt="{TEXT_NEW_DOWNLOADS_IN_CATEGORY_ADDED_TODAY}"><br>
      <!-- END displayNewToDay -->
      <!-- END downloadListLoop -->
      ...
      <!-- END main -->
      


      This does not seem to work correctly.

      Also in the section display NewToDay, if i don't do a ctx.next("displayNewToDay ") will it still print the image or will it skip that section?

      Thanks,
      Dennis Przybyla

        • 1. Re: nested templates
          jae77

          when nesting, you need to prefix the template variable name w/ the same string that you pass into the "next" method.

          ie: TEST_NEW_DOWNLOADS_IN_CATEGORY" should really be:

          displayNewToDay.TEST_NEW_DOWNLOADS_IN_CATEGORY

          and if you don't invoke next, the template won't render the data (that's from the wiki faq).

          be careful using the &lt-- BEGIN tags b/c that will cause the template to look for something to nest/loop over.

          if you want to know where one template starts, and another begins, i recommend just putting just the template name at the start and end of the template's html block.

          i added javadoc to the Context and DelegateContext to try and help w/ some of this, so do an update of those classes to pull the docs. also check the wiki entry that kevin posted.

          • 2. Re: nested templates

            Thanks, I didn't notice the prefix (displayNewToDay.TEST_NEW_DOWNLOADS_IN_CATEGORY) in the tutorial. This fixed most of the problems I was having. However, I am still having problems with the nesting. Here is a snipit of the template:

            <!-- BEGIN displayDetails -->
            
            ...
            
            <!-- BEGIN noRegisteredUsers -->
            <font class="pn-normal">{noRegisteredUsers.TEXT_NO_REGISTERED_USER_VOTES}</font>
            <!-- END noRegisteredUsers -->
            <!-- BEGIN mainRegisteredStatBox -->
            <table border="1" width="200">
            <tr>
            <td valign="top" align="center" colspan="10" bgcolor="#FFFFFF">{mainRegisteredStatBox.TEXT_BREAKDOWN_OF_RATINGS_BY_VALUE}
            </td>
            </tr>
            <tr>
            <!-- BEGIN registeredStatBox -->
            <td bgcolor="#e7e7e7" valign="bottom">
            <img border="0" alt="{registeredStatBox.STAT_ALT}" src="modules/Downloads/images/blackpixel.gif" width="15" height="{registeredStatBox.STAT_HEIGHT}">
            </td>
            <!-- END registeredStatBox -->
            </tr>
            <tr>
            <td colspan="10" bgcolor="#FFFFFF">
            <table cellspacing="0" cellpadding="0" border="0" width="205">
            <tr>
            <td width="10%" valign="bottom" align="center">1
            </td>
            <td width="10%" valign="bottom" align="center">2
            </td>
            <td width="10%" valign="bottom" align="center">3
            </td>
            <td width="10%" valign="bottom" align="center">4
            </td>
            <td width="10%" valign="bottom" align="center">5
            </td>
            <td width="10%" valign="bottom" align="center">6
            </td>
            <td width="10%" valign="bottom" align="center">7
            </td>
            <td width="10%" valign="bottom" align="center">8
            </td>
            <td width="10%" valign="bottom" align="center">9
            </td>
            <td width="10%" valign="bottom" align="center">10
            </td>
            </tr>
            </table>
            </td>
            </tr>
            </table>
            <!-- END mainRegisteredStatBox -->
            
            ...
            
            <!-- END displayDetails -->
            


            And the code using the template:
             displayDownloadDetailContext.put("TEXT_IS_THIS_YOUR_DOWNLOAD", "");
             displayDownloadDetailContext.put("TEXT_ALLOW_OTHER_USERS_TO_RATE", "");
            
             if (numberOfRegisteredVotes == 0)
             {
             DelegateContext noRegisteredUsersContext = displayDownloadDetailContext.next("noRegisteredUsers");
             noRegisteredUsersContext.put("TEXT_NO_REGISTERED_USER_VOTES", "");
             }
             else
             {
             DelegateContext mainRegisteredStatBoxContext = displayDownloadDetailContext.next("mainRegisteredStatBox");
             mainRegisteredStatBoxContext.put("TEXT_BREAKDOWN_OF_RATINGS_BY_VALUE", "");
             for (int i = 0; i < 10; i++)
             {
             DelegateContext registeredStatBoxContext = mainRegisteredStatBoxContext.next("registeredStatBox");
             registeredStatBoxContext.put("STAT_ALT", Integer.toString(registeredVoteList[ i ]) + " (" + registeredPercentPerRating[ i ] + "% )");
             registeredStatBoxContext.put("STAT_HEIGHT", Integer.toString((int)registeredChartHeight));
             }
             }
            


            I am not getting any of the Context text in the registeredStatBox part of the template which is a nested template inside a nested template. The first two levels work fine. Any Ideas?

            Thanks,
            Dennis Przybyla

            • 3. Re: nested templates

              I guess this is an issue I should post in issues. I will create a module that demonstrates the problem and post it in the bug tracking database. I think it should be possable to do more than 1 level deep nested templates and get values to appear in the text. I tried to track it down myself but it seems to exist in a class factory and the render function is empty. So the only thing I can assume is that we are generating a child class from the template and then creating the render function in this new subclass. So not knowing where the render function stuff is I could not track this one down.

              • 4. Re: nested templates
                jae77

                the rendering code is auto generated when the templates are loaded and compiled - it's actually a pretty neat concept, but does make debugging issues a little harder if you don't know where to look.

                definately submit a bug report on this though.

                • 5. Re: nested templates

                  Just to finish this off. I posted a bug report and found that I was doing it wrong.

                  <!-- BEGIN main -->

                  <!-- BEGIN mainLoop -->

                  <!-- BEGIN mainNested -->

                  {mainLoop.mainNested.MY_VARIABLE }

                  <!-- END mainNested -->

                  <!-- END mainLoop -->

                  <!-- END main -->

                  Notice you have to include the first nested loop's name with the current nested loop.