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.

General Questions /

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

Template parsing problems


Reply


4 Posts   1084 Views

Avatar
dompie

Community Member, 88 Posts

1 September 2010 at 5:07am

Edited: 01/09/2010 5:08am

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?

Avatar
swaiba

Forum Moderator, 1804 Posts

1 September 2010 at 6:24am

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.

Avatar
dompie

Community Member, 88 Posts

1 September 2010 at 9:43pm

Edited: 01/09/2010 9:46pm

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

Avatar
swaiba

Forum Moderator, 1804 Posts

1 September 2010 at 10:09pm

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.