Smarty is one of the most famous PHP template engines in the industry, using PHP as a template for PHP templates. It separates the logical code from the external content, provides an easy to manage and use method to separate the PHP code from the
A powerful advantage of smarty is that you can use the Smarty variable directly in the template, eliminating a lot of code, very convenient.
Here are examples of access to page request variables such as get,post,cookies,server,enviroment and
! [! Directory structure, libs is the Smarty Directory, tpls is the template directory, and test. in this directory, tpl uses coms as the compiling Directory. after many experiments, only display echo is output, and the result is 000033334444. why
The following is an example:
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:Copy codeThe Code is as
smarty.class.php The main thing in the classTemplates Release TemplateTemplates_c CacheClass inside $smarty->assign ("Author", "Feng and Meizi")$smarty->display ("Test.tpl")The test.php was looking for a test.tpl file test.tpl:TEST.TPL file replaces
The following are examples of access page request variables such as get, post, cookies, server, enviroment, and session variables. for example, {$ smarty. server. SERVER_NAME} gets the server variable, {$ smarty. env. PATH} obtains the path of the
Example 5-8. date_format [Date Format]Index. php:Copy codeThe Code is as follows:$ Smarty = new Smarty;$ Smarty-> assign ('yesterday', strtotime ('-1 Day '));$ Smarty-> display ('index. tpl ');Index. tpl:{$ Smarty. now | date_format}{$ Smarty. now |
First, comments* Note content *HTML comments are displayed in the client source fileSmarty comments are not sent to the clientSmarty's comments are mainly for the template designer to seeSecond, the variables in the templateL is assigned by PHP file1
In the Smarty template is mainly based on variables, the following is about smarty three variables and some common usageFirst build the file you want to use in the root directory the same as the last time, Configs is the configuration folderOne, the
Equal eq,Ne, neq are not equal,Gt>,Lt is less,Gte and ge are greater than or equal,Less than or equal to lte and le,Not non. mod modulo.Is [not] Can div by be divisible by a certain number,Is [not] whether the even is an even number,$ A is [not]
A page, some data cache, some data is not cached, is the local cacheL $smarty->assign ("var", "value", true)Third parameter: Indicates whether to not cacheL {$var Nocache=true}Use the NoCache parameter after the template variable amountl
First view results --
The page source code is as follows:
Analyze the code. After checking that the index_config.php (Smarty connection file) and index. php files are correct, let's take a look at the template file. The possible reason is
The data table structure of level 2 classification is as follows:
Copy codeThe Code is as follows:The PHP code is as follows:/**@ Document category includes Level 2@ Param int $ rootnum -- number of hash classes@ Param int $ childnum -- number of
: This article mainly introduces the smarty allocation variables of php. if you are interested in the PHP Tutorial, refer to them. Smarty2.php
Require('Smarty/Smarty. class. php ');Require'. /Smarty. inc. php '; global $ _ smarty; $ _ title =
Plug - insis loaded on demand. Plugins are loaded when specific modifiers, functions, resources, and so on are called.Plugin directory variablesCan be a string of a path or an array that contains multiple paths.How to install plug-insis to put the
Delimiter redefinition prevents errors in Smarty template engine parsing when there is JS CSS code in the template!Note the point:The parameters and values in the TPL page template correspond to the relationships in the PHP page.For examplePHP page
Configuration file Prep KnowledgeYou can have the designer manage the global template variables in a file format.One example is the color value of the administrative Template:Usually if you need to change the color theme from the program, you need
PHP pageleft_delimiter=" right_ Delimiter= "}>";//set to false the bounding symbol can have spaces $smarty->auto_literal = false;//add a plugin directory//$smarty- >setpluginsdir (ROOT. " /libs/myplugins/");//Note Add a plug-in, to the system
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.