Discuz! Syntax used in the NT Template

Source: Internet
Author: User

Discuz! The syntax used in the NT template is very small. Our goal is to makeProgramPeople with basic language skills can quickly master it.
The basic statement is as follows:

Syntax Description Example
<% TemplateTplname%> Contains an existing Template File <% Template_ Header%>
{Varname} Show Variables {Username}
{VaR [...]} Display the value of a specified field in the Data variable {Forum [name]}
<% loop item list %>

...

<%/loop %>

the data is listed cyclically. Each data is represented by {item [field name]}, and the data is datatable. <% loop Forum forumlist %>

Forum name: {Forum [name] }

<%/loop %>

<% if ... %>

...

<% else %>

...

<%/if %>

judgment statement, <% else %> is optional, meaning:

if conditions are met...
...
otherwise
...
end

and you can use the following comparison characters:

greater than
==
>=greater than or equal to
<= less than or equal to
! = Not equal to

<% if {userid }==-1 %>
you have not logged on
<% else %>
you have logged on
<%/if %>

<% if {userid }! =-1 %>
you have logged on
<%/if %>

<% CSHARP %>

...

<%/CSHARP %>

insert C # Code <% CSHARP %>

// arbitrary C # code can be inserted
int maxattsize = 20;

<%/CSHARP %>

<% set [(type)] {ref }= ["] Arg ["] %>
<% set
[(type)] {ref }= expression %>
create a program variable and assign values as follows:

type-variable type, if type exists, the object is created first and then assigned a value, otherwise, the value is directly assigned

ref-here represents the variable or attribute

Arg-if this parameter contains double quotation marks, the value is of the string type; if it is a number without double quotation marks, this value is an integer

expression-here you can write an expression to assign a value to ref

Create a variable and assign a value: <% set (INT) {maxattsize }= 20%>
variable reference: <% set (INT) {maxattsize }={ usergroupinfo. maxattachsize }%>
variable value assignment: <% set {maxattsize }= 20%>
method reference: <% set (INT) {FID }={ strtoint ({forumid}) }%>
character type: <% set {forumid} = "5" %>
<% NamespaceNamespacename%> Introduce a namespace
Note: This statement cannot be used in subtemplates.
<% NamespaceDiscuz. forumplugin. Bank%>

Maybe you will be surprised, just a few? Yes, the main display control statements are just a few of the above. If the interface is over 80%, it is enough to use the above statements to solve the problem. Is it very simple?

The above gray background is the Program Statement (deep gray is the advanced syntax, if normal users do not understand the template, you can also do not need to) the program statement format is relatively rigid, so you should pay special attention when writing, the format must be fixed.

The above lists the two most common usage of variables. The following are some exceptions for using variables:

syntax meaning example
{templatepath} path of the template
{ strtoint (...)} convert a numeric string to a number. If the string is not a number, it is converted to 0. It is mainly used when a variable must be converted to a number. <% if {strtoint ({forumid}) }== 1%>

...

{var. Item} the attribute variable contains English characters in the middle. In the generated aspx file, the first character of the attribute is capitalized, mainly used when an object attribute is used the Forum name is {config. forumtitle}

(in the aspx file, the variable is actually config. forumtitle)

{request [...]} obtains the user's submission, including URL parameters and forms. It is mainly used when parameters submitted by the user are to be used <% if {request [username]}! = "" %>

...

So far, the variables and statements required in the template are listed. Of course, if you understand the C # syntax, you can handle it slightly flexibly, only several simple statements are provided here, mainly considering that many webmasters do not have the foundation of programming languages.

Notes

Considering the convenience of writing and reducing the chance of writing errors,Discuz! NT template rules: all variables and statements are in lower caseWe also hope that all the variables provided when you rewrite the Aspx. CS file are in lower case. Only in this way can this rule be maintained.

Generally, a template contains some shared parts. For example, multiple pages share similar headers or menus. Such shared templates are generally called subtemplates, which are only contained on other pages, it is not displayed separately, so no aspx pages need to be generated. To avoid them being generated, and to better distinguish it from other page template files,Discuz! Template rules: All subtemplate file names must start "_", Such as _header.htm

See the http://nt.discuz.net/doc/default.aspx? Cid = 17

In most cases, we strongly recommend that you modify the template style you want based on the template blueprint provided in this document, so that the template creation speed will be faster.

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.