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

Identical left and right delimiters

 
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
Gene.Parmesan
Smarty n00b


Joined: 01 Jun 2011
Posts: 2

PostPosted: Wed Jun 01, 2011 10:43 am    Post subject: Identical left and right delimiters Reply with quote

I'm aware of the change in whitespace around delimiters in order to allow easier compatibility with JavaScript. However, in our case we used identical left and right delimiters (`) instead of the default '{' and '}'. This had always worked fine in Smarty 2, but upgrading to Smarty 3 generates an error.

The error is on the next line after an include:

Code:

`include file="header.tpl" title=""`
<div id="content">


It implies that the right delimiter was not recognized as such, even though there is no trailing space after the right delimiter:

Quote:
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "smarty/templates/index.tpl" on line 2 "&lt;div id=&quot;content&quot;&gt;" - Unexpected "` ", expected one of: "`" , " "' in C:\PHP\includes\sysplugins\smarty_internal_templatecompilerbase.php:431


Turning off auto_literal does not solve the problem. I suspect that the real issue is that identical left and right delimiters are not allowed, but I haven't seen any confirmation of this in the documentation.

It would appear that we're going to need to update all of our templates in order to migrate from Smarty 2 to Smarty 3 - anyone know of any workarounds or settings that would avoid this?[/code]
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Jun 01, 2011 1:35 pm    Post subject: Reply with quote

Yes, the left and right delimiters must be different.
There is no way around it as Smarty3 does allow nested Smarty tags.
Also you should not use for same reasion backticks as delimiter as they have special meaning inside double quoted strings .

It's also a surprise to me that it did work in Smarty2.


Last edited by U.Tews on Wed Jun 01, 2011 1:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jun 01, 2011 1:36 pm    Post subject: Reply with quote

oh, those are nasty delimiters, the "`" is a special character for Smarty inside quotes. Making both delimiters the same character may also be causing problems, but Uwe may respond with a better explanation.

For a quick fix, you could make a prefilter that converts your "`" delimiters to { and } just before compile time, so you don't have to change all your templates. FWIW, I would advise to change the delims and fix the templates with a search/replace.
Back to top
View user's profile Send private message Visit poster's website
Gene.Parmesan
Smarty n00b


Joined: 01 Jun 2011
Posts: 2

PostPosted: Wed Jun 01, 2011 2:15 pm    Post subject: Reply with quote

Fair enough. Might be good to mention in the docs that the delimiters must be different. Indeed identical delimiters mean that the templates cannot be updated with a simple search and replace, so a warning to all you out there who are tempted by the relative simplicity of identical delimiters, a la quotes or Perl regular expressions
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