Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Whitespace in {if} fails

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
me2
Smarty n00b


Joined: 13 Aug 2009
Posts: 3

PostPosted: Thu Aug 13, 2009 8:36 am    Post subject: Whitespace in {if} fails Reply with quote

I'm porting Smarty 2 templates to be compatible with Smarty 3 (latest rev).

I just got this error:
Code:
Code: 0
Error: Syntax Error in template "/var/...l/index.html" on line 214 " <li><a href="/newsletter/">{$NewsletterSubscription }</a></li>" - Unexpected " }", expected one of: "}" , " "
File: /var/.../sysplugins/internal.templatecompilerbase.php
Line: 264

It fails on the space after $NewsletterSubscription. It's nicer not to have spaces at the end of the if-statement, but should it be a Syntax Error?
Back to top
View user's profile Send private message
me2
Smarty n00b


Joined: 13 Aug 2009
Posts: 3

PostPosted: Thu Aug 13, 2009 9:44 am    Post subject: Reply with quote

There more. In Smarty 2 this worked:
Code:
{if ! $smarty.foreach.languages.last} - {/if}


Smarty 3 throws this:
Code:
Code: 0
Error: Syntax Error in template "/var/.../index.html" on line 317 " {if ! $smarty.foreach.languages.last} - {/if}" - Unexpected " ", expected one of: INTEGER , "+" , "-" , "(" , "[" , "$" , "identifier" , "(!,NOT)" , """ , "'" , "boolean" , "null" , "#"
File: /var/.../sysplugins/internal.templatecompilerbase.php
Line: 264


I fixed it by removing the whitespace between the exclamation mark and the variable (which gives prettier code).
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Aug 13, 2009 1:51 pm    Post subject: Reply with quote

Please note that in Samrty3 you can control with with spaces if the standard delimiters ({ and }) used for a Smarty tag or if they are part of javascript.

{something} is a Smarty tag
{ something } is not interpreted by Smarty, for example in Javascript code

The later allows the use of { and } in Javascript without the need to put {literal} tags around it.

There are some other cases where Smarty 3 currenty does not like withespaces where Smarty 2 did. It is an open task to make the lexer/parser of Smarty 3 more tolerant for whitspaces.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP