How to concatenate strings in the smarty template _ PHP Tutorial

Source: Internet
Author: User
The string concatenation method in the smarty template. Copy the code from the PHP page to the variables uploaded to the Smarty template (here, two variables are created on the Smarty instead) as follows: {assignvarnamevalueRichard. lee} {assignvaragev PHP page to the variables uploaded to the Smarty template (used here, two variables are created on the Smarty)

The code is as follows:


{Assign var = "name" value = 'Richard. Lil '}
{Assign var = "age" value = '27 '}



1. output in a certain position of the Smarty template (Richard. Lee --- 27)
Splicing method: {$ name | cat: "---" | cat: $ age}
Explanation: concatenates variables $ name, "---", and $ age into a string.

2. if you want to output (name: Richard. Lee, Age: 27) somewhere in the Smarty template, the splicing method is as follows:

The code is as follows:


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

Explanation: The two splicing methods have the same effect.

Note: The method found on the Internet is not very understandable | cat:, but after two simple examples, it is concluded that | cat: can be considered as a symbolic link string, it is equivalent to the point (.) in the PHP file (.).

Usage (here, two variables are created on Smarty instead) code: {assign var = "name" value = 'Richard. lee '} {assign var = "age" v...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.