For a long time did not use Smarty to do projects, and today suddenly to change their own website inside some things, because my site is a long time ago with smarty template engine do, change some places on the feeling still have to search the answer on the Internet, it seems to the long-lost Smarty has started unfamiliar, hurriedly tutorial. Make a summary of the variable operator of the Smarty template for later use.
Smarty Template Variable operator introduction
Capitalize [initial capitalization], example: {$smarty. get.name|capitalize}
Count_characters [Count characters], example: {$smarty. get.name|count_characters}
Cat [Connection string], example: {$smarty. Get.name|cat: ' Welcome to Www.phpernote.com '}, connect two variables such as: {$smarty. get.name|cat:$ Smarty.get.password}
Count_paragraphs [Count of paragraphs], example: {$smarty. get.name|count_characters}
Count_sentences [Calculation of sentences], example: {$smarty. get.name|count_sentences}
Count_words [Count words], example: {$smarty. Get.name|count_words}
Date_format [Time format], 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 as: 2012-7-31 11:01:21
Default, Example: {$smarty. Get.name|default: ' phpernote.com '}, which means that when the name parameter is not accepted or the value of the name parameter received is empty, Use phpernote.com instead of this value.
Escape [Transcode], example: {$smarty. get.name|escape: ' url '}?
indent [indent], example: {$smarty. Get.name|indent:10: '}, the first line of the paragraph is indented, and here is an example of a character that indents 10 spaces. The function is similar to the text-indent inside the CSS.
lower [lowercase], example: {$smarty. Get.name|lower}
Upper [uppercase], example: {$smarty. Get.name|upper}
NL2BR [replace \ n (line break) in variable with
], example: {$smarty. GET.NAME|NL2BR}
Regex_replace [Regular substitution], example: {$smarty. Get.name|replace: "/[\r\t\n]/": "Phpernote.com"}, replacing the regular content in a variable with the specified content
Replace [replace], example: {$smarty. Get.name|replace: "baidu.com": "Phpernote.com"}, replacing the content required in the variable with the specified content, The example means replacing all baidu.com in a variable with phpernote.com.
Spacify [intervening spaces], example: {$smarty. get.name|spacify: "^^"}, inserts the variable character between the characters and the specified content, including spaces.
String_format [string formatting], example: {$smarty. Get.namestring_format: "%d"}, the action is to format the contents of the variable, formatting parameters similar to PHP's printf.
Strip [Remove (extra spaces)], example: {$smarty. Get.name|strip: ""}, if there is a first argument, replace the space with the specified content, the example means to replace the space with "";
strip_tags [HTML tag removal], example: {$smarty. Get.name|strip_tags}
truncate [intercept], example: {$smarty. get.name|truncate:10: ' ... '}, the example means to intercept 10 characters, the excess part is replaced with "...", the second argument is empty, the outside part is omitted directly.
WordWrap [line width constraint], example: {$smarty. get.name|wordwrap:30: "\ n": true}, forcing a newline of content that exceeds the specified length
Today is listed here, will be gradually supplemented and perfected, more specific smarty template variable operator knowledge you can refer to the Smarty Handbook!
Articles you may be interested in
- Use PHP functions in Smarty Templates and how to use multiple functions for a variable in a smarty template
- Smarty Variable operator Summary
- Smarty Template Retention Variables Summary
- Summary of System variables commonly used in thinkphp templates
- How to generate random numbers in a smarty template
- Escaping user-passed variables, from Ecshop
- How constants defined by define in the program are used in the Smarty template
- Smarty include file methods for using variables
http://www.bkjia.com/PHPjc/764136.html www.bkjia.com true http://www.bkjia.com/PHPjc/764136.html techarticle For a long time did not use Smarty to do the project, today suddenly to change their own website inside some things, because my site is a long time ago with the Smarty template engine to do, change to some places ...