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

variables that contain delmiters error
Goto page Previous  1, 2
 
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 -> General
View previous topic :: View next topic  
Author Message
U.Tews
Administrator


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

PostPosted: Mon Jan 05, 2015 9:07 pm    Post subject: Reply with quote

Some general notes about Smarty, not discussing if your general approach is best practice or not.

1. Never run template output thru fetch() in a loop as template output at some point could contain Smarty delimiters resulting in syntax errors like the ones you did experience.

2. If you have variables which contains Smarty tags you could run it through the eval plugin as mentioned before.
See http://www.smarty.net/docs/en/language.function.eval.tpl
But each time {eval} is used it does result in a call of the compiler (same as calling fetch() multiple times.
This will result in bad performance of the solution.

3. Having said the above you should avoid variable containing Smarty tags.
If variables like your {$name} are assigned in your PHP script you should not have a problem to replace {$first} {$last} with real value.
If the string "{$first} {$last}" is generated by a plugin you could same thing because you can get the current values of $first and $last within the plugin as follow:
Code:

$first = $template->getTemplateVars('first');
$last = $template->getTemplateVars('last');


See http://www.smarty.net/docs/en/api.get.template.vars.tpl
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jan 05, 2015 10:41 pm    Post subject: Reply with quote

maorbari wrote:
But now the problem is:
Value of variable $name is "{$first} {$last}".

That's exactly the problem. Template variables SHOULD NOT contain Smarty formatting. Ever.
Rethink your logic, may be write a plugin for what you are trying to do. Or use template inclusion already.
Make a subtemplate with "{$first} {$last}" and include it where necessary.
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 -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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