Smarty template variable operator summary_php tutorial

Source: Internet
Author: User
Smarty template variable Operator summary. I haven't used Smarty for a project for a long time. today, I suddenly want to modify some of my website's content, because my website was made a long time ago using the smarty template engine, I have not used Smarty for projects in some places for a long time. today, I suddenly want to modify some of my website's content, because my website was made using the smarty template engine a long time ago, I felt I had to search for the answer on the internet in some places. it seems that the long-lost smarty has been getting unfamiliar, so I have to study it quickly. Summarize the variable operators in the Smarty template for future use.

Introduction to variable operators in the Smarty Template

Capitalize [uppercase letters], for example: {$ smarty. get. name | capitalize}

Count_characters [count characters], for example: {$ smarty. get. name | count_characters}

Cat [connection string], example: {$ smarty. get. name | cat: 'Welcome to www.phpernote.com '}. connect two variables, for example, {$ smarty. get. name | cat: $ smarty. get. password}

Count_paragraphs [calculates the number of paragraphs], for example: {$ smarty. get. name | count_characters}
 
Count_sentences [calculates the number of periods], for example: {$ smarty. get. name | count_sentences}

Count_words [count words], example: {$ smarty. get. name | count_words}

Date_format [time format], for example: {$ smarty. server. request_time | date_format: "% Y-% m-% d % H: % M: % S"} or {$ smarty. now | date_format: "% Y-% m-% d % H: % M: % S"}. display format: 11:01:21

Default [default], example: {$ smarty. get. name | default: 'phpernote. com '}, which indicates that phpernote.com is used to replace the value when the name parameter is not accepted or the received name parameter value is null.
 
Escape [transcoding], example: {$ smarty. get. name | escape: 'URL '}?

Indent [indent], for example: {$ smarty. get. name | indent: 10: ''}, indent the first line of the paragraph. The example here is indented by ten characters in space. The function is similar to text-indent in css.

Lower [lower case], example: {$ smarty. get. name | lower}

Upper [upper case], example: {$ smarty. get. name | upper}

Nl2br [replace \ n (linefeed) in the variable
], For example: {$ smarty. get. name | nl2br}

Regex_replace [regular expression replacement], for example: {$ smarty. get. name | replace: "/[\ r \ t \ n]/": "phpernote.com"}, replace the regular content in the variable with the specified content.

Replace [replace], for example: {$ smarty. get. name | replace: "baidu.com": "phpernote.com"}. replace the content required in the variable with the specified content. In this example, replace all baidu.com in the variable with phpernote.com.

Spacify [inserted blank], for example: {$ smarty. get. name | spacify: "^"}, inserts the specified content between the variable and character, including spaces.

String_format [string formatting], for example: {$ smarty. get. namestring_format: "% d"}. this operation is to format the content in the variable. the formatting parameter is similar to the printf of php.

Strip [remove (extra space)], example: {$ smarty. get. name | strip: ""}. if the first parameter exists, the space is replaced with the specified content. In this example, the space is replaced "";
 
Strip_tags [remove html tags], example: {$ smarty. get. name | strip_tags}

Truncate [truncate], for example: {$ smarty. get. name | truncate: 10 :'... '}. The example indicates 10 characters are intercepted. the excess part is "... "Replace. if the second parameter is null, the excess part is omitted directly.

Wordwrap [row width constraint], for example: {$ smarty. get. name | wordwrap: 30: "\ n": true}, force line feed of content beyond the specified length

I have listed it here today. it will be supplemented and improved later. For more details about the variable operators in the Smarty template, refer to the Smarty manual!

Articles you may be interested in
  • Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
  • Smarty variable Operator summary
  • Smarty template retention variable summary
  • Summary of common system variables in Thinkphp templates
  • How to generate a random number in the smarty Template
  • Escape user-passed variables, from ecshop
  • How to use constants defined by define in a program in a smarty Template
  • How to use variables in smarty include file

...

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.