Home » Php » php – Smarty local variable concatenation with string

php – Smarty local variable concatenation with string

Posted by: admin April 23, 2020 Leave a comment


How to assign a local template variable with a string concatenated just like below:


to be used below in the code in the manner {$yes_src}.

How to&Answers:

The way you are doing it is call the “short form” of assign, you just need to use the correct quoting mechanism:


Use assign:

{assign var="yes_src" val="`$const1`yes`$const2`"}

Use cat:


You can also simply put the variables next to one another without assigning it to a variable:


… no variable needed.

A note If you find yourself using assign more than rarely, you might have a misconception about the ideas of separating logic from presentation. Usually, concatenation and other variable work would be accomplished in PHP before the template is ever involved. The template’s role is to just display the data, you should avoid creating or altering the data in the template.



{ $yes_src = $variable|cat:"some string"|cat:$variable }


Try this:

{capture assign=yes_src}{$const1}.'yes'.{$const2}{/capture}

And then use the new variable: