A method for concatenating strings in an smarty template

  • 2021-01-03 20:51:24
  • OfStack

PHP page to the Smarty template variable (here, create two variables on Smarty instead)


{assign var="name" value='Richard.Lee'}
{assign var="age" value='27'}


1. Want to output at a certain position in the Smarty template (ES9en. Lee-- 27)
{$name|cat:"-- "|cat:$age}
Explanation: Concatenates the variables $name, "-- ", and $age into 1 string

2. Want to output (name: ES22en. Lee, age: 27) at a certain position in the Smarty template, stitching method:

{" Name: "|cat:$name|cat:" Age: "|cat:$age}
{" Name: "|cat:$name|cat:" . "|cat:" Age: "|cat:$age}

Explanation: The effect of two splicing methods is one

Note: the method found on the Internet does not understand the function of |cat: very well, but after two simple examples, a simple conclusion can be drawn: |cat: can be regarded as the symbol of the link string, equivalent to the point (.) in the PHP file.


Related articles: