Hongmu Notes
Home Program Notes Apple cms template development manual
Program Notes Apple cms

Apple cms template development manual

Apple cms template development manual

Development Template

To create a theme, first create a template; theme_tpl Create a custom template directory, then create an  HTML folder  to store all your HTML files.

└─ template
   └─ `theme_tpl`
       ├─ css
       ├─ js
       └─ html

For detailed information, please refer to the "Template Structure" section to build your template structure; this section primarily covers development techniques and does not provide detailed step-by-step construction instructions. Developing any website template requires a certain level of expertise. html css And; javascript Ensure you have a solid front-end foundation.

essentialjs

The built-in `home.js` file already includes a wide range of essential features; developers can simply import it to start using the object-encapsulated functions provided – such as history tracking, favorite/ dislike functionality, visitor traffic statistics, comments, and more – often referred to as the "Three Must-Have Features" for Apple CMS templates.

<script src="{$maccms.path}static/js/jquery.js"></script>
<script>var maccms={"path":"__ROOT__","mid":"{$maccms['mid']}","url":"{$maccms['site_url']}","wapurl":"{$maccms['site_wapurl']}","mob_status":"{$maccms['mob_status']}"};
</script>
<script src="{$maccms.path}static/js/home.js"></script>

#use tags

AppleCMS v10 fully supports TP5 syntax; PHP variables enclosed in {} within HTML are supported, e.g. {$maccms['site_name']}The array format can be used instead of, e.g.:{$maccms.site_name}The list tag consists of a start tag and an end tag. For example: {maccms:vod type="all" num="10"}{/maccms:vod}Internal variables consist of database fields and are prefixed with $vo; e.g.:{$vo.vod_name}{$vo.vod_id}   and so on.

#Use function

We often need to apply functions to the template output variables; you can use the following:

{$data.name|md5}
  • The compiled result is:
    <?php echo (md5($data['name'])); ?>
  • If a function requires multiple parameters to be passed, use:
    {$create_time|date="y-m-d",###}

The `DATE` function accepts two parameters, separated by commas; in this case, the first parameter is `y-m-d`, and the second parameter is the `create_time` variable that needs to be output. Since this variable is the second parameter, it must be marked with `###` to indicate its position. The resulting compiled code is:

<?php echo (date("y-m-d",$create_time)); ?>

If the previously defined variable serves as the first parameter in a later-defined function, it can be used directly:

{$data.name|substr=0,3}

Indicates output

<?php echo (substr($data['name'],0,3)); ?>

Alternatively, you can also use:

{$data.name|substr=###,0,3}

However, there is absolutely no need for this. It also supports filtering using multiple functions; simply separate the functions with a |, for example:

{$name|md5|strtoupper|substr=0,3}

The compiled result is:

<?php echo (substr(strtoupper(md5($name)),0,3)); ?>

 

The functions will be called in left-to-right order. If you find this approach cumbersome, you can simply write them like this:

{:substr(strtoupper(md5($name)),0,3)}

 

The functions used for variable output can support built-in PHP functions, user-defined functions, or even static methods.

#Commonly used processing functions

  • Multiple functions may be used; all functions should be separated by the '|' symbol.

  • For all image URLs—whether remote or local—it is recommended to use ; mac_url_img Process it.

  • {:mac_data_count(0,'all','vod')}Get total number of videos

  • {:mac_data_count(0,'today','vod')}Get the total number of today's updated videos

  • {:mac_data_count(0,'all','art')}Get total number of articles

  • {:mac_data_count(0,'today','art')} Get the total number of updated articles for today

  • {:mac_data_count(1,'all')}Retrieve the total amount of data for a specific category (supporting videos and articles); requires the category ID as input.

  • {:mac_data_count(1,'today')} Retrieve the total number of today's update entries for a specific category (supporting both videos and articles); requires the category ID as input.

  • Additionally, it also supportstopic,website,actor,roleModule data acquisition volume

  • {:mac_url('map/index')} Retrieve internal site links; the parameter represents the module/page.

  • {$obj.vod_content|mac_url_content_img} If third-party attachment storage is used, the default URL for attachments and images starts with `mac:`; this method will replace it with ` http`.

  • {$vo.vod_pic|mac_url_img} Automatically convert image URLs

  • {$vo.vod_content|mac_substring=100}Return a substring of 100 characters.

  • {$vo.vod_content|mac_filter_html}Return content without HTML code.

  • {$vo.actor|mac_url_create='actor','vod','search','&nbsp;'} Generates N search links from a string of characters connected by a separator; the last two parameters can be omitted – they default to generating VOD module search links. For example, this function can be used to create search links for actors. It supports fields such as actor, director, tag, and extended category. The last parameter specifies the separator used to separate the generated links.

  • {$vo.vod_time|mac_day} – Automatically returns the date

  • {$vo.vod_time|mac_friend_date} – Friendly time reminder: a few seconds ago, a few minutes ago, a few hours ago, a few days ago...

  • {$vo.vod_year|mac_default= 'Unknown'} If the string is empty, the default string is returned.

  • {$user.user_login_ip|mac_long2ip} – Return a formatted IP address

  • {$user.user_id|mac_get_user_portrait} – Get user profile image URL

#Commonly used JS processing functions

The `class` attribute of elements is typically used for automatic event binding.

  • Member – Save Video Content
<a href="javascript:;" class="mac_ulog" data-type="2" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}">我要收藏</a>
  • Member – Favorite Articles Page
<a href="javascript:;" class="mac_ulog" data-type="2" data-mid="{$maccms.mid}" data-id="{$obj.art_id}">我要收藏</a>
  • Member – Favorite Special Content Page
<a href="javascript:;" class="mac_ulog" data-type="2" data-mid="{$maccms.mid}" data-id="{$obj.topic_id}">我要收藏</a>

This content is typically placed before the end of the `<body>` tag; it is not intended for display but is used solely for storing user information.

  • Member – Article Viewing History
<span style="display:none" class="mac_ulog_set" alt="设置文章内容页浏览记录" data-type="1" data-mid="{$maccms.mid}" data-id="{$obj.art_id}" data-sid="{$param.sid}" data-nid="{$param.nid}"></span>
  • Member – Special Feature Viewing History
<span style="display:none" class="mac_ulog_set" alt="设置专题内容页浏览记录" data-type="1" data-mid="{$maccms.mid}" data-id="{$obj.topic_id}" data-sid="{$param.sid}" data-nid="{$param.nid}"></span>
  • Member – Video Viewing History
<span style="display:none" class="mac_ulog_set" alt="设置内容页浏览记录" data-type="1" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}" data-sid="{$param.sid}" data-nid="{$param.nid}"></span>
  • Members – Video Playback History
<span style="display:none" class="mac_ulog_set" alt="设置视频播放记录" data-type="4" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}" data-sid="{$param.sid}" data-nid="{$param.nid}"></span>
  • Member-Video download record
<span style="display:none" class="mac_ulog_set" alt="设置视频播放记录" data-type="5" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}" data-sid="{$param.sid}" data-nid="{$param.nid}"></span>
  • Videos, articles, topics like and dislike general
<a class="digg_link" data-id="{$obj.vod_id}{$obj.art_id}{$obj.topic_id}" data-mid="{$maccms.mid}" data-type="up" href="javascript:;">
  顶<em class="digg_num">{$obj.vod_up}{$obj.art_up}{$obj.topic_up}</em>
</a>
<a class="digg_link" data-id="{$vod_id}{$art_id}{$topic_id}" data-mid="{$maccms.mid}" data-type="down" href="javascript:;">
  踩<em class="digg_num">{$obj.vod_down}{$obj.art_down}{$obj.topic_down}</em>
</a>

#Video, article, topic clicks display Universal

Total clicks:

<span class="mac_hits hits" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}{$obj.art_id}{$obj.topic_id}" data-type="hits"></span>
  • Daily clicks:
<span class="mac_hits hits_day" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}{$obj.art_id}{$obj.topic_id}" data-type="hits_day"></span>
  • Weekly hits:
<span class="mac_hits hits_week" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}{$obj.art_id}{$obj.topic_id}"  data-type="hits_week"></span>
  • Monthly clicks:
<span class="mac_hits hits_month" data-mid="{$maccms.mid}" data-id="{$obj.vod_id}{$obj.art_id}{$obj.topic_id}" data-type="hits_month"></span>
  • Foreground browsing history call
<a href="javascript:;" class="mac_history">历史记录</a>

#Write browsing history on video, article, and topic details pages

<span style="display:none" class="mac_history_set" alt="设置视频历史记录" data-name="[{$obj.type.type_name}]{$obj.vod_name}" data-pic="{$obj.vod_pic|mac_url_img}"></span>
<span style="display:none" class="mac_history_set" alt="设置文章历史记录" data-name="[{$obj.type.type_name}]{$obj.art_name}" data-pic="{$obj.art_pic|mac_url_img}"></span>
<span style="display:none" class="mac_history_set" alt="设置专题历史记录" data-name="{$obj.topic_name}" data-pic="{$obj.topic_pic|mac_url_img}"></span>
  • Visiting the page triggers a scheduled task, and it is recommended to place it at the bottom of the homepage; Since the entry file name is variable, the default is api.php. If you need to modify it, please customize data-file="xxx.php"
<span style="display: none;" class="mac_timming" data-file="" ></span>
  • Website navigation history record statistics; it is recommended to place it at the bottom of the homepage. The source domain name must be consistent with the jump URL in the website navigation.
<span style="display: none;" class="mac_referer" data-file="" ></span>
  • Automatically obtain short URL link
<input type="text" name="shorten" class="mac_shorten" />
  • Custom usage of short URL, obtained by js
<script>
    MAC.Shorten.Get("http://www.baidu.com/",function(r){
        alert(r.data.url_short);
    });
</script>
  • Obtain user record logs, such as 1 browse, 2 collection, 3 want to watch, 4 on demand, 5 download
  • MAC.Ulog.Get has 4 parameters type type 0 represents all, page number, limit number of entries per page, call callback function
<script>
    MAC.Ulog.Get(0,1,999,function(r){
        if(r.code == 1){
            $.each(r['list'],function(index,row){
                console.log(row['data']['id'] + '--' + row['data']['name'] + '--' + row['data']['pic'] + '--' + row['data']['link'] + '--' + row['data']['type']['type_name'] + '--' + row['data']['type']['link'] + '--'  );
            });
        }else{
			console.log('获取失败');
        }
	});
</script>

#Use default value

We can provide default values ​​for variable outputs, for example:

{$obj.user_nickname|default="这个人没有昵称"}

Default value output can still be supported for system variables, for example:

{$obj.vod_actor|default="演员为空"}

Default values ​​and functions can be used together, for example:

{$Think.get.name|getName|default="名称为空"}

#Use operators

We can use operators on template output, including support for “+”“-” “*” “/” and “%”. For example:

operatorUsage example
+{$a+$b}
-{$a-$b}
*{$a*$b}
/{$a/$b}
%{$a%$b}
++{$a++} or {++$a}
--{$a--} or {--$a}
Comprehensive judgment{$a+$b*10+$c}

When using operators, regular function usage is no longer supported, for example:

{$user.score+10} //正确的
{$user['score']+10} //正确的
{$user['score']*$user['level']} //正确的
{$user['score']|myFun*10} //错误的
{$user['score']+myFun($user['level'])} //正确的

#ternary operation

Templates can support ternary operators, for example:

{$status? '正常' : '错误'}
{$info['status']? $info['msg'] : $info['error']}
{$info.status? $info.msg : $info.error }

Version 5.0 also supports the following writing methods:

{$varname.aa ?? 'xxx'}

Indicates that if $varname is set, $varname will be output, otherwise 'xxx' will be output. The parsed code is:

<?php echo isset($varname['aa']) ? $varname['aa'] : '默认值'; ?>
{$varname?='xxx'} 

Outputs `xxx` only when `$varname` is true. The parsed code is:

<?php if(!empty($name)) echo 'xxx'; ?>
{$varname ?: 'no'}

This means that if $varname is true, then output $varname; otherwise, output "no". The parsed code is as follows:

<?php echo $varname ? $varname : 'no'; ?>
{$a==$b ? 'yes' : 'no'}

前面的表达式为真输出yes,否则输出no, 条件可以是==, ===,!=,!==, >=, <=

#Template inheritance

Template inheritance is a more flexible approach to template-based layout design; it differs from traditional template layouting and, in fact, should be considered a higher-level layer within the template layout architecture. Template inheritance is quite straightforward to understand—it's similar to class inheritance: you can define a base template (or layout) that contains relevant blocks, and then create a child template by extending this base template to override the blocks defined within it.

Therefore, the advantage of template inheritance lies in allowing blocks (`block`) within the base template to be replaced by corresponding blocks in the child template.

Each block consists of the {block} {/block} tags. Below is a typical block design from the basic template (used for designing a website title):

{block name="title"}<title>网站标题</title>{/block}

The `block` tag must specify a `name` attribute to identify the name of the current block; this identifier should be unique within the current template. The `block` tag can contain any template content, including other tags and variables, for example:

{block name="title"}<title>{$web_title}</title>{/block}

You can even load external files into a block:

{block name="include"}{include file="Public:header" /}{/block}

A template can define any number of distinct block names; for example, the following defines a base.html template:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>{block name="title"}标题{/block}</title>
   </head>
   <body>
      {block name="menu"}菜单{/block}
      {block name="left"}左边分栏{/block}
      {block name="main"}主内容{/block}
      {block name="right"}右边分栏{/block}
      {block name="footer"}底部{/block}
   </body>
</html>

Then, we use inheritance within the child template (which is actually the entry template for the current operation):

{extend name="base" /}
{block name="title"}{$title}{/block}
{block name="menu"}
<a href="/" >首页</a>
<a href="/info/" >资讯</a>
<a href="/bbs/" >论坛</a>
{/block}
{block name="left"}{/block}
{block name="main"}
{volist name="list" id="vo"}
<a href="/new/{$vo.id}">{$vo.title}</a><br/>
 {$vo.content}
{/volist}
{/block}
{block name="right"}
 最新资讯:
{volist name="news" id="new"}
<a href="/new/{$new.id}">{$new.title}</a><br/>
{/volist}
{/block}
{block name="footer"}
{__block__}
 @ThinkPHP 版权所有
{/block}

In the above example, we can see that the `extend` tag is used within a child template to inherit the `base` template. Within a child template, block definitions from the base template can be overridden; if no override is specified, the original block definition from the base template is retained; if an empty block is defined, the content of that block in the base template is removed. In this example, we have removed the content of the `left` block and overridden the content of all other blocks.

{block name="footer"}
{__block__}@大图模板datll.com 版权所有
{/block}

This block contains the `{_block_}` tag; when this tag is present in a block, it does not simply reload that block directly – instead, it indicates that the content of the block corresponding to the inherited template should be referenced at this position; as a result, this block represents the merged content. Therefore, the final content of the `footer` block is: "Bottom @ Large Image Template – Copyright  "; The usage of the `extend` tag is identical to that of the `include` tag; you can also load other templates:

{extend name="Public:base" /}

Alternatively, use an absolute file path for loading.

{extend name="./Template/Public/base.html" /}

In the current sub-template, you can only define blocks and not other template content, otherwise it will be ignored directly, and only blocks that have been defined in the base template can be defined. For example, if the following definition is taken:

{block name="title"}<title>{$title}</title>{/block}
<a href="/" >首页</a>
<a href="/art/index" >资讯</a>
<a href="/actor/" >明星</a>

The navigation section will be invalid and will not appear in the template. Templates can be inherited at multiple levels. For example, B inherits A, and C inherits B. Eventually, the blocks in C will overwrite the blocks with the same name in B and A, but the blocks in C and B must have been defined in A. The order of block definitions in sub-templates is arbitrary. The key to using template inheritance lies in how the basic template is laid out and designed. If combined with the original layout function, it will be more flexible.

#comparetags

Comparison tags are used for simple variable comparisons. Complex judgment conditions can be replaced with if tags. Comparison tags are a set of tags, and their usage is basically the same, as follows:

labelmeaning
eq or equalequal
neq or notequalnot equal to
gtgreater than
egtGreater than or equal to
ltless than
eltless than or equal to
heqConstant equal to
nheqnot equal to

Their usage is basically the same, the difference is that the conditions for judgment are different, and all comparison tags can be used together with the else tag. For example, to require the value of the name variable to be output if it is equal to value, you can use:

{eq name="name" value="value"}value{/eq}

perhaps

{equal name="name" value="value"}value{/equal}

It can also be mixed with else tags:

{eq name="name" value="value"}
相等
{else/}
不相等
{/eq}

When the value of the name variable is greater than 5, output

{gt name="vod_name" value="5"}value{/gt}

Output when the value of the name variable is not less than 5

{egt name="name" value="5"}value{/egt}

The variables in the comparison tag can support object attributes or arrays, or even system variables. For example: When the attributes of the vo object (or array, or automatic judgment) are equal to 5, output

{eq name="vo.vod_name" value="5"}
{$vo.vod_name}
{/eq}

When the attribute of the vo object is equal to 5, it is output

{eq name="vo:vod_name" value="5"}
{$vo.vod_name}
{/eq}

When $vo['vod_name'] is equal to 5, output

{eq name="vo['vod_name']" value="5"}
{$vo.name}
{/eq}

It also supports the use of functions on variables. When the string length of the attribute value of the vo object is equal to 5, it will be output.

{eq name="vo:name|strlen" value="5"}{$vo.name}{/eq}

Variable names can support Thinkphp5.0 system variables, for example:

{eq name="Think.get.name" value="value"}相等{else/}不相等{/eq}

The value of a tag is typically a string or a number; if you need to use a variable, simply prefix it with the `$` symbol: Output when the property of the `vo` object equals `$a`.

{eq name="vo:vod_name" value="$a"}{$vo.vod_name}{/eq}

All comparison tags can be uniformly replaced with the `compare` tag (in fact, all comparison tags are aliases for the `compare` tag); for example: if the value of the `name` variable equals 5, then output.

{compare name="name" value="5" type="eq"}value{/compare}

Equivalent to

{eq name="name" value="5" }value{/eq}

The value of the `type` attribute is the name of the comparison tag listed above.

#Conditional judgment

#SWITCH tag

use:

{switch name="变量" }
    {case value="值1" break="0或1"}输出内容1{/case}
    {case value="值2"}输出内容2{/case}
    {default /}默认情况
{/switch}

How to use it:

{switch name="User.level"}
    {case value="1"}value1{/case}
    {case value="2"}value2{/case}
    {default /}default
{/switch}

The `name` attribute can use functions and system variables; for example:

{switch name="Think.get.userId|abs"}
    {case value="1"}admin{/case}
    {default /}default
{/switch}

The `value` attribute of a `case` statement can support multiple conditional checks; use `|` to separate the conditions, for example:

{switch name="Think.get.type"}
    {case value="gif|png|jpg"}图像格式{/case}
    {default /}其他格式
{/switch}

Indicates that if $_GET["type"]  is gif, png or jpg, it will be judged as an image format.

The Case tag also has a break attribute, indicating whether a break is required. By default, break will be added automatically. If you do not want a break, you can use:

{switch name="Think.get.userId|abs"}
    {case value="1" break="0"}admin{/case}
    {case value="2"}admin{/case}
    {default /}default
{/switch}

You can also use variables for the value attribute of the case, for example:

{switch name="User.userId"}
    {case value="$adminId"}admin{/case}
    {case value="$memberId"}member{/case}
    {default /}default
{/switch}

When using the variable method, simultaneous judgment of multiple conditions is no longer supported.

Simple usage

{switch $User.userId}
    {case $adminId}admin{/case}
    {case $memberId}member{/case}
{/switch}

#IF tag

Usage examples:

{if condition="($name == 1) OR ($name > 100) "} value1
{elseif condition="$name eq 2"/}value2
{else /} value3
{/if}

In addition, we can use PHP code in the condition attribute, for example:

{if condition="strtoupper($user['name']) neq 'THINKPHP'"}ThinkPHP
{else /} other Framework
{/if}

The condition attribute can support dot syntax and object syntax, for example: Automatically determine whether the user variable is an array or an object

{if condition="$user.name neq 'ThinkPHP'"}ThinkPHP
{else /} other Framework
{/if}

Or know that the user variable is an object

{if condition="$user:name neq 'ThinkPHP'"}ThinkPHP
{else /} other Framework
{/if}

Since the condition attribute of the if tag basically uses PHP syntax, it will be more concise to use judgment tags and switch tags as much as possible. In principle, if it can be solved with switch and comparison tags, try not to use if tags. Because switch and comparison tags can use variable modifiers and system variables. If the IF tag still cannot meet certain special requirements, you can use native PHP code or PHP tags to write code directly. Simple usage

{if condition="表达式"}
{if (表达式)}
{if 表达式}

The results of these three writing methods are the same

#Range judgment

The range judgment tags include in notin between notbetween tags, all of which are used to judge whether the variable is in a certain range.

#IN and NOTIN

Usage: Assume that the id in our controller is assigned a value of 1:

$id =    1;
$this->assign('id',$id);

We can use the in tag to determine whether a template variable is within a certain range, for example:

{in name="id" value="1,2,3"}
id在范围内
{/in}

Finally, it will be output: id is within the range.

If the judgment is not within a certain range, you can use the notin tag:

{notin name="id" value="1,2,3"}
id不在范围内
{/notin}

Finally, it will be output: id is not in the range. The above two tags can be combined into:

{in name="id" value="1,2,3"}
id在范围内
{else/}
id不在范围内
{/in}

The name attribute can also support direct determination of system variables, for example:

{in name="Think.get.id" value="1,2,3"}
$_GET['id'] 在范围内
{/in}

For more system variable usage, please refer to the system variables section.

The value attribute can also use variables, for example:

{in name="id" value="$range"}
id在范围内
{/in}

The $range variable can be an array or a comma-separated string.  The value attribute can also use system variables, for example:

{in name="id" value="$Think.post.ids"}
id在范围内
{/in}

#BETWEEN and NOTBETWEEN

You can use the between tag to determine whether a variable is within a certain interval. You can use:

{between name="id" value="1,10"}
输出内容1
{/between}

Similarly, you can also use the notbetween tag to determine that a variable is not within a certain range:

{notbetween name="id" value="1,10"}
输出内容2
{/notbetween}

You can also use the else tag to combine the two usages, for example:

{between name="id" value="1,10"}
输出内容1
{else/}
输出内容2
{/between}

When using the between tag, the value only needs an interval range, that is, only two values ​​are supported, and the following values ​​are invalid, for example

{between name="id" value="1,3,10"}
输出内容1
{/between}

The actual judgment range is 1~3, not 1~10. String judgment can also be supported, for example:

{between name="id" value="A,Z"}
输出内容1
{/between}

The name attribute can use system variables directly, for example:

{between name="Think.post.id" value="1,5"}
输出内容1
{/between}

The value attribute can also use variables, for example:

{between name="id" value="$range"}
输出内容1
{/between}

The value of a variable can be a string or an array, and system variables can also be supported.

{between name="id" value="$Think.get.range"}
输出内容1
{/between}

#RANGE

You can also use the range tag directly to replace the previous judgment usage:

{range name="id" value="1,2,3" type="in"}
输出内容1
{/range}

The value of the type attribute can be in/notin/between/notbetween, and the usage of other attributes is consistent with IN or BETWEEN.

#PRESENT NOTPRESENT tag

The present tag is used to determine whether a variable has been defined. Usage:

{present name="name"}
name已经赋值
{/present}

If it is judged that there is no assignment, you can use:

{notpresent name="name"}
name还没有赋值
{/notpresent}

The above two tags can be combined into:

{present name="name"}
name已经赋值
{else /}
name还没有赋值
{/present}

The name attribute of the present tag can directly use system variables, for example:

{present name="Think.get.name"}
$_GET['name']已经赋值
{/present}

#EMPTY NOTEMPTY tag

The empty tag is used to determine whether a variable is empty. Usage:

{empty name="name"}
name为空值
{/empty}

If it is judged that there is no assignment, you can use:

{notempty name="name"}
name不为空
{/notempty}

To merge the above two tags into:

{empty name="name"}
name为空
{else /}
name不为空
{/empty}

The name attribute can use system variables directly, for example:

{empty name="Think.get.name"}
$_GET['name']为空值
{/empty}

#DEFINED tag

The DEFINED tag is used to determine whether a constant is defined. The usage is as follows:

{defined name="NAME"}
NAME常量已经定义
{/defined}

The value of the name attribute must be strictly case-sensitive.

If the judgment is not defined, you can use:

{notdefined name="NAME"}
NAME常量未定义
{/notdefined}

The above two tags can be combined into:

{defined name="NAME"}
NAME常量已经定义
{else /}
NAME常量未定义
{/defined}

#tag nesting

The template engine supports the multi-level nesting function of tags, and you can specify whether the tags in the tag library can be nested.

The built-in system tags – including `volist`, `switch`, `if`, `elseif`, `else`, `foreach`, `compare` (covering all comparison tags), `(not)present`, `(not)empty`, `(not)defined`, and others – can all be used in nested fashion. For example:

{volist name="list" id="vo"}
    {volist name="vo['sub']" id="sub"}
        {$sub.name}
    {/volist}
{/volist}
  • The outer nested loop is used to classify internal videos or articles; the key focus is on assigning unique IDs and keys to both the external and internal tags. By default, the system uses the term "vo," which may lead to data loss.
{maccms:type ids="1,2,3,4" order="asc" by="sort" id="vo1" key="key1"}
    {maccms:vod num="10" type="'.$vo1['type_id'].'" order="desc" by="time" id="vo2" key="key2"}
        {$vo1.type_name}:{$vo2.vod_name};
    {/maccms:vod}
{/maccms:type}
  • Nested loops for primary and secondary classification data
{maccms:type ids="1,2,3,4,5" order="asc" by="sort" id="vo" key="key"} 				  
	{maccms:type parent="'.$vo['type_id'].'" order="asc" by="sort" id="vo2" key="key2"} 
		<li><a href=":mac_url_type($vo2)}">{$vo2.type_name}</a></li>
	{/maccms:type}
{/maccms:type}

#Use PHP

PHP code can be used in combination with HTML tags within template files; you can write any PHP statements directly inside the template file, using one of the following two methods:

#Use php tag

{php}echo 'Hello,world!';{/php}

We recommend using PHP tags whenever possible when writing PHP code, as native PHP syntax may be disabled by server configuration, which could lead to parsing errors.

#Use native php code

<?php echo 'Hello,world!'; ?>

Note: HTML tags (including both standard HTML tags and XML tags) cannot be used within PHP tags or PHP code; therefore, the following methods are无效:

{php}{eq name='name'value='value'}value{/eq}{/php}

The PHP tag uses an `eq` tag; therefore, it is invalid.

{php}if( {$user} != 'ThinkPHP' ) echo  'ThinkPHP' ;{/php}

The PHP tag uses the ordinary {$user} tag to output a variable; therefore, this is invalid.

{php}if( $user.name != 'ThinkPHP' ) echo  'ThinkPHP' ;{/php}

The PHP tag uses the `$user.name` syntax for outputting a variable, which is invalid.

In short, it is not allowed to use code that PHP itself does not support within PHP tags.

If the `tpl_deny_php` parameter is set to `true`, native PHP code cannot be used within templates; however, output using PHP tags is still supported.

#Custom Tag

`ASSIGN` tag – The `ASSIGN` tag is used to define variables within a template file; its usage is as follows:

{assign name="var" value="123" /}

When the template is executed, a variable named `var` is assigned the value 123.

The `value` attribute also supports variables; for example:

{assign name="var" value="$val" /}

Alternatively, you can directly assign a system variable to the `var` variable; for example:

{assign name="var" value="$Think.get.name" /}

This is equivalent to executing: $var = $_GET['name'];

DEFINE Tag: The DEFINE tag is used to define constants within a template; its usage is as follows:

{define name="MY_DEFINE_NAME" value="3" /}

When the template is executed, a constant named MY_DEFINE_NAME is defined.

The `value` attribute supports variables (including system variables), for example:

{define name="MY_DEFINE_NAME" value="$name" /}

perhaps

{define name="MY_DEFINE_NAME" value="$Think.get.name" /}
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Apple cms commonly used processing functions

Apple cms commonly used processing functions Program Notes Apple cms

Multiple functions are allowed, separated by | {:mac_data_count(0,'all','vod')} Get the total number of videos {:mac_data_count(0,'today','vod')} Get the total number of updated videos today {:mac_data_count(0,'all','art')} Get the total number of articles {:ma…
👁 261

Recommended reading

Responsive Fishery Association Website Template 1151

Responsive Fishery Association Website Template 1151 Practical Collection Yiyou template

An EyouCMS responsive website template designed specifically for fishing associations. Its professional fishing-themed design effectively showcases the association's functions, member services, industry news, and fishing-related information, helping fishing associations establish an online industry exchange platform. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 51
Brand Tea E-commerce Website Template – 11195 0536

Brand Tea E-commerce Website Template – 11195 0536 Practical Collection Yiyou template

A professional EyouCMS template designed for e-commerce platforms specializing in branded tea sales. Its modern e-commerce design seamlessly showcases tea products, brand stories, promotional campaigns, and online purchasing options. This template helps tea brands establish online e-commerce platforms and expand their sales channels. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (E...
👁 47
(PC+WAP) Metal Hose Website Template – Hardware Products Website Source Code Download – 1114

(PC+WAP) Metal Hose Website Template – Hardware Products Website Source Code Download – 1114 Practical Collection pbootcms Template

A PbootCMS website template for metal hoses and hardware products, compatible with both PC and WAP devices. The professional industrial design is ideal for showcasing metal hose products, hardware items, and industrial applications. This template helps pipe and hardware manufacturers showcase their products online and attract industrial customers. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 53
(PC+WAP) Smart Eco-Friendly Equipment Website – pbootCMS Template; Blue Marketing-oriented Machinery Website Source Code Download – 0534

(PC+WAP) Smart Eco-Friendly Equipment Website – pbootCMS Template; Blue Marketing-oriented Machinery Website Source Code Download – 0534 Practical Collection pbootcms Template

An intelligent eco-friendly equipment solution paired with a PbootCMS marketing website template for the machinery industry – featuring a blue color scheme and compatibility with both PC and WAP devices. The page design focuses on maximizing conversion rates while effectively highlighting the technical advantages and real-world application scenarios of these smart eco-friendly devices. This template helps environmental machinery companies attract more targeted online customer inquiries and enhance their brand visibility. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin...
👁 44
Public Relations Association Website Template 1152

Public Relations Association Website Template 1152 Practical Collection Yiyou template

This EyouCMS template is ideal for Public Relations Associations, featuring a professional and sophisticated design that effectively showcases the association's functions, member services, industry trends, and PR activities. It helps PR associations establish an online information exchange platform. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS System...
👁 49