Home  >  Article  >  Backend Development  >  Method of splicing strings in smarty template_PHP tutorial

Method of splicing strings in smarty template_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:001275browse

The variables passed from the PHP page to the Smarty template (replaced here by creating two variables on Smarty)

Copy the code The code is as follows:

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


1. Want to output at a certain position in the Smarty template (Richard.Lee---27)
Splicing method: {$name|cat:"---"|cat:$age}
Explanation: The variables $name, "---", and $age are spliced ​​into a string

2. If you want to output (name: Richard.Lee, age: 27) at a certain position in the Smarty template, the splicing method is:
Copy code The code is as follows:

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

Explanation: The effect obtained by the two splicing methods is the same

Remarks: The method found on the Internet does not fully understand the role of |cat:, but after two simple examples, a simple conclusion can be drawn: it can be |cat: regarded as the symbol of the link string, equivalent to the dot (.) in the PHP file.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825259.htmlTechArticleThe variables passed from the PHP page to the Smarty template (replaced here by creating two variables on Smarty) Copy code The code is as follows: {assign var="name" value='Richard.Lee'} {assign var="age" v...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn