Capture means capturing in Chinese. its function is to capture the data output from the template. when we need it, call it to get the purpose of capturing data.
1. capture tag
Capture means capturing in Chinese. its function is to capture the data output from the template. when we need it, call it to get the purpose of capturing data. Example:
View copy print?
- {Capture name = test}
- {/Capture}
- {$ Smarty. capture. test}
{capture name=test} {/capture} {$smarty.capture.test}
Note:
Content between {capture name = "test"} and {/capture} is stored in the variable $ test, which is specified by the name attribute. in the template, use $ smarty. capture. test accesses this variable. if the name attribute is not specified, the function uses "default" as the parameter by default.
2. config_load label
Config_load can directly read the content in the file, which saves the assign step.
View copy print?
- Test.csv:
- PageTitle = "config_load_test"
- BodyBgColor = "# eeeeee"
- Img = "girl.jpg"
- Width = "100"
- Height = "100"
- Index. tpl:
- {Config_load file = "test.csv "}
- {# PageTitle #}
-
test.csv:pageTitle = "config_load_test"bodyBgColor = "#eeeeee"img = "girl.jpg"width="100"height="100"index.tpl:{config_load file="test.csv"}{#pageTitle#}
In the above process, if the following problem occurs: Warning: Smarty error: unable to read resource, please verify if your test.csv file is in the configuration directory of smarty. the default configuration directory is configs.
View copy print?
- /**
- * The directory where config files are located.
- *
- * @ Var string
- */
- Var $ config_dir = 'configs ';
/** * The directory where config files are located. * * @var string */ var $config_dir = 'configs';
3. Use of literal labels
For web development, JavaScript and jquery code will inevitably be written. In js and jquery, there will be symbols like {}. will smarty understand it as a php variable? If you do not add the literal label, smarty will certainly understand the variable, and it will not, for example:
View copy print?
- {Literal}
- Function getAbsLeft (e ){
- Var l = e. offsetLeft;
- While (e = e. offsetParent) l + = e. offsetLeft;
- Return l;
- }
- Function getAbsTop (e ){
- Var t = e. offsetTop;
- While (e = e. offsetParent) t + = e. offsetTop;
- Return t;
- }
- {/Literal}
{literal}function getAbsLeft(e){ var l=e.offsetLeft; while(e=e.offsetParent)l+=e.offsetLeft; return l;} function getAbsTop(e){ var t=e.offsetTop; while(e=e.offsetParent)t+=e.offsetTop; return t;}{/literal}
4. php labels
When you get used to assign, have you ever thought about writing php code directly in the template file? I think sometimes you must think about it. For example:
View copy print?
- {Php}
- Global $ result;
- Foreach ($ result as $ key => $ value ){
- Echo "key = $ key, value => $ value
";
- }
- {/Php}
{php}global $result;foreach($result as $key=>$value){echo "key=$key,value=>$value
";}{/php}
5. strip tag
Strip labels remove spaces and carriage return characters from the labels. I think that mobile phone developers must use them, because spaces in the full corner may lead to disorder throughout the page, even a blank page. The mobile phone screen is small, and it is estimated that there is a low possibility of using smarty.
View copy print?
- {Strip}
- Strip
- {/Strip}
{strip} strip{/strip}
6. fetch label
The file_get_contents in the root php of the fetch tag can read the content in the file and is a string.
View copy print?
- {Fetch file = "./aaaa.txt" assign = "result "}
- {If is_array ($ result )}
- Is array
- {Else if}
- Not array
- {/If}