: This article mainly introduces the discuz template syntax. if you are interested in the PHP Tutorial, refer to it. Discuz! The parsing of the X template is mainly for./source/class/class_template.php file parsing. For more information, see this file!
-
Template nesting syntax
Resolve the content of the nested template into PHP statements and merge them into the writing method in this template.
The common/header corresponds to the header.html template file in the common directory of a template.
Include nested template content when running the program
Note: When there are many loops in the template, use subtemplate whenever possible.
-
Logic judgment if... else
- If the code is written in an HTML form element, you can avoid making the code clearer and easier to read, for example, {if $ my_var} xxx {/if}
Arbitrary html statement // It is especially important to judge an attribute value of an html tag. if it is outside the tag, it is best to add Annotator
- If statement with branch conditions
Arbitrary html statement Arbitrary html statement
- If statement with multiple conditions, you can use the bitwise operator in the regular PHP judgment.
Arbitrary html statement
- When CSS is written, you can set the settings according to the conditions, for example:
// As mentioned above, comments can be omitted when determining the attribute values in html tags.
-
Directly execute the PHP code tag:
// Equivalent
// Equivalent
// Equivalent
// Equivalent
// Equivalent
-
Directly output variables, equivalent to PHP's The curly braces can be omitted but are not recommended to be removed. (The Module program can be called here after processing ):
// The output content is generally not a simple variable.
// Usage condition: 1-the variable must be processed by the function. 2-The output is a variable, not an array.
-
Embedded point code of the advertisement:
// This is an embedded discuz advertisement. we recommend that you customize the ad space. the custom ad space will automatically generate the call code in the background. you only need to paste and copy the code.
-
Hook tag of the plug-in:
Hook is a keyword that defines index_top as a hook.
-
Loop syntax (multiple loops are allowed)
Circular writing with array keys
HTML statement output by loop
Circular writing without array keys
HTML statement output by loop
-
DIY region and background data call labels:
// Do not use the diy function of discuz as much as possible, because the maintenance is very large, you can directly use the background custom module or module code
{Block XXX} (data call module)
-
Discuz! After the language pack is loaded, use in the template file:
{Lang forum_category_modedby}
The language pack is stored in the./source/language/directory as a PHP array.
The above introduces the discuz template syntax, including the content, hope to be helpful to friends interested in PHP tutorials.