Tell smarty to print block as is
I need to 开发者_运维百科inline some javascript code into the Smarty template files and these {ldelim} {rdelim} things are killing me. Is there a way to tell smarty to ignore the markup for a block and just output it as is? Something similar to CDATA blocks in the xml?
Just in case: here is how simple javascript looks now:
$(function() {ldelim}
$( "#slides" ).accessNews({ldelim}
speed : "{$speed}",
slideBy : 1
{rdelim});
{rdelim});
creepy heh?
Re your update: You can use {literal} .... insert content here {/literal}
to turn off Smarty variable parsing for entire blocks.
Old answer: I like to change the default delimiter characters to something else for this exact reason. (As far as I know, that can be done for the whole project only though, so you would have to see whether it's for you.)
For example to
<( $variablename )>
(just my personal favourite, use whatever suits you)
The variables to change are the rightDelimiter
and leftDelimiter
properties. Documentation
$smarty = new Smarty();
$smarty->left_delimiter = '<(';
$smarty->right_delimiter = ')>';
Using the {literal} tag is useful in this case, but as Pekka said it is very annoying to close and begin tags every time you want to insert a variable. You can change the delimiter characters of Smarty, but that's not so good if you already have lots of templates.
The Smarty team resolved this problem in Smarty 3. No more {literal} tags and the template works fine. Maybe you could try updating it.
精彩评论