Jump to:

23483 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Template parsing problems

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1010 Views
  • dompie
    Avatar
    Community Member
    88 Posts

    Template parsing problems Link to this post

    Hello, i am currently Yahoo tracking code and have problems with the templating engine.

    The code i am implementing looks like:

    <script type="text/javascript">
       /*globals YWA*/
       var YWATracker = YWA.getTracker('xxxx');
       <% if Menu(3) %>
          YWATracker.setDocumentGroup('/$Level(1).URLSegment/$Level(2).URLSegment');
          YWATracker.setCF(8, '$Level(1).MenuTitle');
          YWATracker.setCF(9, '$Level(2).MenuTitle');
          YWATracker.setCF(10, '$Level(3).MenuTitle');
       <% else_if Menu(2) %>
          YWATracker.setDocumentGroup('$Level(1).URLSegment');
          YWATracker.setCF(8, '$Level(1).MenuTitle');
          YWATracker.setCF(9, '$Level(2).MenuTitle');
       <% else %>
          YWATracker.setDocumentGroup('$Level(1).URLSegment');
          YWATracker.setCF(8, '$Level(1).MenuTitle');
       <% end_if %>
       
       YWATracker.setDocumentName('$ElementName');
       YWATracker.setDomains('$YahooDomains');
       YWATracker.setCF(7, '$Locale.Nice');
       YWATracker.setCF(11, 'XXXX');
       YWATracker.submit();
    </script>

    The HTML output is:

    <script type="text/javascript">
       /*globals YWA*/
       var YWATracker = YWA.getTracker('xxxx');
       
          YWATracker.setDocumentGroup('/about-us/brand-model');
          YWATracker.setCF(8, 'About Us');
          YWATracker.setCF(9, 'Brand Model');
          YWATracker.setCF(10, '');
       <% else_if Menu(2) %>
          YWATracker.setDocumentGroup('about-us');
          YWATracker.setCF(8, 'About Us');
          YWATracker.setCF(9, 'Brand Model');
       
       
       YWATracker.setDocumentName('about-us-brand-model');
       YWATracker.setDomains('XXXX');
       YWATracker.setCF(7, 'English');
       YWATracker.setCF(11, 'XXXX');
       YWATracker.submit();
    </script>

    I also tried with double-quotes inside the <script> tags, but it did not change anything (incl. flush). Did i miss something? Any hints how to solve this issue?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Template parsing problems Link to this post

    I find elseif's and complex if statements can cause problems. I'd place more of the code into a function of the controller or do this...

    <% if Menu(3) %>
    YWATracker.setDocumentGroup('/$Level(1).URLSegment/$Level(2).URLSegment');
    YWATracker.setCF(8, '$Level(1).MenuTitle');
    YWATracker.setCF(9, '$Level(2).MenuTitle');
    YWATracker.setCF(10, '$Level(3).MenuTitle');
    <% else %>
    <% if Menu(2) %>
    YWATracker.setDocumentGroup('$Level(1).URLSegment');
    YWATracker.setCF(8, '$Level(1).MenuTitle');
    YWATracker.setCF(9, '$Level(2).MenuTitle');
    <% else %>
    YWATracker.setDocumentGroup('$Level(1).URLSegment');
    YWATracker.setCF(8, '$Level(1).MenuTitle');
    <% end_if %>
    <% end_if %>

    Hope this helps and by the way there is a separate section of the forum for template questions.

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Template parsing problems Link to this post

    Thanks, works great. But I have much more complicated if statements on other places in my code and they work without problems...
    However, i stumbled upon another problem. Is it possible to pass more than one argument to a Page method from Template?
    As soon as i enter a comma inside Template tags, i receive an 'Parse error: syntax error, unexpected T_ELSE in'.
    E.g.:

    <% if Modulus(3, 5) %>

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Template parsing problems Link to this post

    Going back to my first point ("I'd place more of the code into a function of the controller ") - I usually do the heavy lifting in the controller rather than in the template... have a read of this...

    http://www.silverstripe.org/template-questions/show/290473?start=0#post290481

    ...I'd advise you do the work of building your dataobjects up in the controller so that it is straightforward to iterate over them in the template. Remember all the functions called in the template are available in straight php in the controller.

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