|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Sat Mar 17, 2012 6:25 am Post subject: Rendering string as template (.tpl file) |
|
|
How can I render a string as normal template?
In my case, I have a $template PHP variable, that is the contents of a .tpl file stored in database or somewhere else.
To display that template, I need to treat it first as a normal template.
snapshot: eg.
Code: |
<?php
$template = "
Hello {$id|name},
Thank you for your registration, ....
Your membership will expire in {$expiry}.
...
";
?>
|
Is there a way to handle/render this? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Mar 17, 2012 9:16 am Post subject: |
|
|
Smarty3 has two build in resource types for it. "string" and "eval".
Code: |
$template = 'some template source....';
$smarty->display("string:$template");
$smarty->display("eval:$template");
|
The string resource does store the compiled template code and it does create also a cache file when caching is enabled. Note that it creates a separate compiled and cache file for each source string. So it should be used only if you have reoccuring strings.
The eval resource will not save compiled code, so it calls the compiler on every single call. So it has much less performance but is usefull if the strings never look teh same.
You can use these resources also as subtemplates.
Code: | {include "string;$foo"} |
|
|
Back to top |
|
|
|
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
|