开发者

adding content in the middle of smarty variable

开发者 https://www.devze.com 2023-03-02 11:12 出处:网络
how can I modify a smarty variable on tpl file and add some data after certain position without using php? is it possible?

how can I modify a smarty variable on tpl file and add some data after certain position without using php? is it possible?

suppose,

$var="this is test content for a variable";

and i wan开发者_StackOverflow中文版t to add "EXTRA DATA " after 8th character position so that the final output will be "this is EXTRA DATA test content for a variable"


You could do it like this:

{$var|substr:0:8}EXTRA DATA {$var|substr:8}

May I ask why you're not wanting to do this in PHP? It's more suited there, this is not the job that a template should be doing.


yes you can truncate the sentencen use http://www.smarty.net/docs/en/language.modifier.truncate.tpl

then add your extra word as smarty varible

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号