Separated from Discuz template class and syntax

Source: Internet
Author: User

Template principle: When the template is not compiled into a PHP file, the system automatically compiles the template for the first time and then directly reads the PHP file when the template is opened again.

Main functions

  1. Removed the Discuz Language Pack feature.
  2. Port all functions in the Discuz Template
  3. Added the automatic cache update and lifecycle functions.

The method used in the template is the same as that in Discuz, so no extra explanation is required. You only need to make some simple settings before using the template.

If you need to use the discuz Language Pack function, just remove the 172nd line comment of template. class. php and add the original deleagevar function of discuz to template. func. php.

Java code
  1. // Set language Variables

  2. Function compute agevar ($ var ){
  3. Return
    $ GLOBALS [
    'Language'
    ] [$ Var]? $ GLOBALS [
    'Language'
    ] [$ Var]: "! $ Var !";
  4. }
// Set the language variable function variable agevar ($ var) {return $ GLOBALS ['language'] [$ var]? $ GLOBALS ['language'] [$ var]: "! $ Var !";}

Discuz! The template uses the syntax similar to the PHP expression.
.

Directly output variables: {$ abc} or {echo $ abc}

Output a variable in the array: {$ arr [0]}

Reference Other templates in this template. For example, you can write the header template file (header.htm) as follows: {subtemplate header}

The following elements are supported: * <! -{... }->

Logical element delimiter, which is used to contain conditions and cyclic elements.
Condition judgment
<! -- {If expr1} -->
Statement1
<! -- {Elseif expr2} -->
Statement2
<! -- {Else} -->
Statement3
<! -- {/If} -->
This is a typical condition template. When the condition expr1 is true, the template statement1 content is displayed; otherwise, when expr2
If it is true, the template statement2 content is displayed; otherwise, the template statement3 content is displayed. Like condition control in other languages
<! -{Elseif expr}-> and <! -{Else}-> is optional.

Array loop without subscript Variables
<! -- {Loop $ array $ value} -->
Statement
<! -- {/Loop} -->
An array loop statement equivalent to PHP:
Foreach ($ array as $ value ){
Statement
}

Array loop with subscript Variables
<! -- {Loop $ array $ key $ value} -->
Statement
<! -- {/Loop} -->
An array loop statement equivalent to PHP:
Foreach ($ array as $ key => $ value ){
Statement
}

The logical element delimiter {} contains the html annotator <! -
-> In addition to distinguishing information elements, Dreamweaver and Frontpage are also convenient.
And other tools to edit the template. Because logical elements are recognized as html
The comment is not displayed. For the vast majority of users, the content in the logical element does not need to be modified at all. Even modifying the wrong character may cause the error message and the entire system cannot run. Therefore
When using a template, do not modify the logical information of the template, or add internal elements of the logical information (such as <! -{Else}->
). Otherwise, an error may occur. If your template is accidentally modified or damaged, immediately use the original standard default template to overwrite it.

For experts, actually external <! --> It can be omitted and can be used to locate certain elements in the template. However, it is strongly recommended that you do not try it easily.
*{... }
Information element delimiter
O {constant}
You can reference the interface to replace variables, which must be uppercase letters. The actual purpose of this symbol is to reference the PHP constant, so you can also reference other constant content through it.
O {Lang variable}
You can reference the variable content of the language variable in the template. The language variable is passed through the array in templates. php. Lang.
$ Language definition. For example, the content of {Lang post_edit} is replaced with $ language ['Post _ edit'] During template compilation.
".
O {Template Name}
Template Embedding Operator. To avoid the lengthy template, you can use this symbol to embed the content of the name Template into this template (which is actually referenced ).

{Subtemplate header} // This is a static introduction, that is, the header code is directly loaded into the current cache file.

{Template header} // This is a dynamic introduction and will be introduced through include.
O {eval statement}
Eval
Labels are mainly used to execute PHP in the template.
Syntax, In the eval
Followed by legal PHP
Syntax. We recommend that you use this structure only when necessary, because it will damage the structure and readability of the template. For example, {eval echo 'template! ';} Implements echo 'template ';

O {lf}

Line Break, because discuz! The template engine ignores unnecessary line breaks (/n). This symbol is used to generate a/n.

Recommended template modification method: You can use a normal editor to manually write HTML or use Dreamweaver or FrontPage.
Modify. However, you must remember not to modify the positions and content of elements in the same logical element or nested element. That is, you cannot <! -{}->
The surrounding content can be moved separately, and cannot be deleted. However, the entire external logical structure can be moved or deleted.

If the following error message Parse error: parse error, unexpected '}' is output on the page where the template is located after modification
/Home/username/forums/forumdata/templates/login login.tpl.php on line
6. The template contains logical elements that cannot be matched or are incorrectly formatted. Check whether the elements do not match, are not terminated or nested, and the format is incorrect, if necessary, the original template can be restored.
Problem.

Discuz! Provides a convenient interface packaging program. The format has been described earlier. paste the exported information content to the style solution in system settings.
In the import interface solution, execute. The program will automatically parse the data content, restore the relevant interface settings, customize the replacement variables and the required template settings. If the exported interface uses a non-default template, you must
./Set the templates Directory attribute to 777 to enable the import program to automatically create template records and folders.

Definition variable description

<? Exit?>
<! -{Eval $ I = 2}->
<! -{If $ I = 1}->
123
<! -{/If}->

<! -{Block name = "spaceblog"
Parameter = "notype/1/order/I. dateline, I. lastpost/limit/0, 14/cachetime/900
/Cachename/newti/tpl/data "}-> <! -The latest log is used to call the data in the database.
->
<! -{Eval $ I = 0;}->
<! -{Loop $ _ SBLOCK ['newti'] $ value}->
<! -{If $ I % 2 = 0}-> // if the remainder of I divided by 2 is equal to 0
<Div class = "listbg"> <! -{Else}->
<Div class = "listbg2"> <! -{/If}->
· [<Span class = "listA"> $ value [typename] </span>] <
Class = "listA" href = "$ value [url]" title = "$ value [subjectall]" target = "_ blank"> $ value [subject] </a> </div>
<! -{Eval $ I ++;}->
<! -{/Loop}->

<! -{Eval for ($ I = 1; $ I <= 5; $ I ++) {}->

<! -{Eval echo "Hello World! <Br/> ";}->
<! -{Eval }}->

 

 

From: http://hudeyong926.iteye.com/blog/899385

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.