Concatenation in smarty

后端 未结 3 1350
醉梦人生
醉梦人生 2021-02-05 05:28

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         


        
相关标签:
3条回答
  • 2021-02-05 05:34

    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

    0 讨论(0)
  • 2021-02-05 05:38

    such an expression will do the trick:

    {$product1_photo = "{$smarty.const.IMG_URL}/{$pInfo.PhotoName}"}
    
    0 讨论(0)
  • 2021-02-05 05:59

    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
    
    0 讨论(0)
提交回复
热议问题