1,capture Label
Capture's Chinese meaning is crawl, its function is to crawl the data of the template output, when we need it, call it to get the purpose of fetching data. Example:
The code is as follows |
Copy Code |
1.{capture Name=test} 2. 3.{/capture} 4.<div class= "image" > 5.{$smarty. Capture.test} 6.</div>
|
Description
The content between {capture Name= "test"} and {/capture} is stored in the variable $test, which is specified by the Name property. The variable is accessed in the template by $smarty. capture.test. If the Name property is not specified, The function defaults to use "default" as an argument, which is very jquery in the clone
2,config_load Label
Config_load can read the contents of a file directly, so you can save assign this step.
The code is as follows |
Copy Code |
1.test.csv: 2.pageTitle = "Config_load_test" 3.bodyBgColor = "#eeeeee" 4.img = "Girl.jpg" 5.width= "100″ 6.height= "100″ 7.INDEX.TPL: 8.{config_load file= "Test.csv"} 9.10.<title>{#pageTitle #}</title> 11.<body bgcolor= "{#bodyBgColor #}" > 12. 13.</body> 14. |
If such a problem arises 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 Configs
The code is as follows |
Copy Code |
1./** 2.* the directory where config files are located. 3.* 4.* @var String 5.*/ 6.var $config _dir = ' configs '; 3, |
Use of literal labels
Do web development, will inevitably write some js,jquery code. JS and jquery inside will {} Such symbols, Smarty will it be interpreted as a PHP variable? If you don't add a literal tag, Smarty will definitely understand the variable and not add it, for example:
The code is as follows |
Copy Code |
1.{literal} 2.function Getabsleft (e) { 3.var L=e.offsetleft; 4.while (e=e.offsetparent) l+=e.offsetleft; 5.return l; 6.} 7.function Getabstop (e) { 8.var T=e.offsettop; 9.while (e=e.offsetparent) t+=e.offsettop; 10.return T; 11.} 12.{/literal}
|
4,php Label
When you get used to assign, do you have any thought, in the template file directly write PHP code, I think sometimes you must really want to. For example:
The code is as follows |
Copy Code |
1.{php} 2.global $result; 3.foreach ($result as $key => $value) { 4.echo "key= $key,value=> $value <br>"; 5.} 6.{/php} 5, |
Strip label
Strip label to remove the space and enter the label, which I think, do mobile phone development friends definitely use, because the full-width space may cause the entire page confusion, or even a blank page. The cell phone screen is small, the likelihood of using smarty is also relatively small.
The code is as follows |
Copy Code |
1.{strip} 2.<div> 3.<font color= "Red" >strip</font> 4.</div> 5.{/strip} 6,fetch Label |
Fetch tag root php file_get_contents Think, can read the contents of the file, and is a string of the situation
code is as follows |
copy code |
1.{fetch File= "./aaaa.txt" assign= "Result"} 2.{ If Is_array ($result)} 3.<b>is array</b> 4.{ else if} 5.<b>not array</b> 6.{ /if} |