Home  >  Article  >  Backend Development  >  smarty模板中拼接字符串的方法_PHP

smarty模板中拼接字符串的方法_PHP

WBOY
WBOYOriginal
2016-06-01 11:55:50796browse

PHP页面传到Smarty模板上的变量(这里用,在Smarty上创建两个变量代替)
复制代码 代码如下:
{assign var="name" value='Richard.Lee'}
{assign var="age" value='27'}


1、想要在Smarty模板的某个位置输出(Richard.Lee---27)
拼接方法:{$name|cat:"---"|cat:$age}
解释:将变量$name、"---"、$age 拼接成一个字符串

2、想要在Smarty模板的某个位置输出(姓名:Richard.Lee,年龄:27),拼接方法:
复制代码 代码如下:
{"姓名:"|cat:$name|cat:",年龄:"|cat:$age}
{"姓名:"|cat:$name|cat:","|cat:"年龄:"|cat:$age}

解释:两个拼接方法得到的效果一样

备注:在网上找到的方法,不是很理解|cat:的作用,但是经过两个简单的例子得出简单结论:可以把|cat:当成是链接字符串的符号,相当于PHP文件中的点(.)。

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