Home >Backend Development >PHP Tutorial >Practical tips for php smarty template engine
Explanation: The content between {capture name="test"} and {/capture} is stored in the variable $test, which is specified by the name attribute. Access this variable through $smarty.capture.test in the template. If the name attribute is not specified, the function will use "default" as a parameter by default, which is similar to the clone method in Jquery. Second, config_load tag config_load can directly read the contents of the file, thus eliminating the assign step. example: test.csv file:
then template index. The above test.csv file can be referenced in the tpl file as follows:
Note: If a problem like Warning: Smarty error: unable to read resource occurs during the above process, please check whether your test.csv is placed in the smarty configuration directory. The default configuration directory is the configs directory. . Three, php tag After getting used to assigning, have you ever thought about writing PHP code directly in the template file? Although this is not recommended, what should you do when you have to do this due to business needs? Take a look at this example:
Four, strip tag The function of the strip tag is to remove spaces and carriage returns within tags. I personally feel that this tag is quite useful. It can compress the final output HTML format. If you want to see the effect, just look at the source code of this site. Yes Not cool, hehe:
Five, fetch tag The fetch tag has similar functions to the function file_get_contents in PHP. Both can read the contents of the file, and the read result can be assigned to a variable in the form of a string, as shown in the following use case:
Six, use constants Constants defined using define in php can be used directly in smarty templates Instructions: {$smarty.const.The constant name you defined} |