Concatenation in smarty

喜你入骨 提交于 2019-12-03 15:22:41

问题


I want to assign the value obtained from the concatenation of these two variables with a string.

{assign var="url" value="{$WS_PATH}aircraft_images/{$images[i].image}"}

Please let me know how can we do this in smarty.


回答1:


One of these should work:

{assign var="url" value=$WS_PATH|cat:"aircraft_images/"|cat:$images[i].image}

Or

{assign var="url" value="`$WS_PATH`aircraft_images/`$images[i].image`"}

I am not sure if the $images[i].image will be parsed correctly, you may have to {assign} it to another variable first




回答2:


You've used assign properly.

A simplified example could look like this:

yourphpfile.php:

$tpl = new Smarty;
$tpl->assign('var1','Hello');
$tpl->assign('var2','World');
$tpl->display('yourtemplate.tpl');

yourtemplate.tpl:

...
<body>
{assign var="url" value="{$var1} - and - {$var2}"}
{$url}
</body>

...will result to the output:

Hello - and - World



回答3:


such an expression will do the trick:

{$product1_photo = "{$smarty.const.IMG_URL}/{$pInfo.PhotoName}"}


来源:https://stackoverflow.com/questions/10023042/concatenation-in-smarty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!