In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what are the tips of php smarty template engine". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the tips of php smarty template engine?"
Capture tag
Capture means grab in Chinese, and its function is to grab the data output from the template. When we need it, we call it to get the purpose of grabbing the data. Examples are as follows:
The copy code is as follows:
{capture name= "test"}
{/ capture}
{$smarty.capture.test}
Description: the content between {capture name= "test"} and {/ capture} is stored in the variable $test, which is specified by the name attribute. Access the variable through $smarty.capture.test in the template. If the name property is not specified, the function defaults to "default" as an argument, similar to the clone method in Jquery.
Config_load tag
Config_load can read the contents of the file directly, thus omitting the step of assign, as shown in the following example:
Test.csv file:
The copy code is as follows:
PageTitle = "config_load_test"
BodyBgColor = "# eeeeee"
Img = "girl.jpg"
Width= "100"
Height= "100"
The above test.csv file can be referenced in the template index.tpl file as follows:
The copy code is as follows:
{config_load file= "test.csv"}
{# pageTitle#}
Note: if there is such a problem in the above process Warning: Smarty error: unable to read resource, please check to see if your test.csv is placed in the smarty configuration directory. The default configuration directory is the configs directory.
Php tag
When you get used to assign, have you ever thought about writing php code directly in the template file, which is not recommended, but sometimes what should you do when you have to do so due to the needs of the business? Look at the following example:
The copy code is as follows:
{php}
Global $result
Foreach ($result as $key= > $value) {
Echo "key=$key,value= > $value
"
}
{/ php}
Strip tag
The function of the strip tag is to remove the spaces in the tag and enter. I think this tag is quite useful. It can compress the final output html format. If you want to see the effect, just take a look at the source code of this site, isn't it cool? hehe:
The copy code is as follows:
{strip}
Strip
Php smarty strip compresses html output, www.phpernote.com to see the effect of source code
{/ strip}
Fetch tag
The fetch tag has the same function as the function file_get_contents in php. It can read the contents of the file and assign the read result to a variable in the form of a string, as shown in the following use case:
The copy code is as follows:
{fetch file= ". / aaaa.txt" assign= "result"}
{if is_array ($result)}
Is array
{else if}
Not array
{/ if}
Use constant
Constants defined with define in php can be used directly in smarty templates
The method of use is as follows:
The copy code is as follows:
{$smarty.const. The constant name you defined}
At this point, I believe you have a deeper understanding of "what are the tips of the php smarty template engine?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.