Home > Article > Backend Development > Empire CMS list template listvar supports program code
1. When adding a template, the list.var template needs to check the "Use program code" option. As shown in the picture:
2. Add PHP code directly, no need to add
list.var Template example:
Example 1: If the information does not set a title image, display the specified image.
1if(empty($r[titlepic])) 2{ 3 $r[titlepic]='/images/img.gif'; 4} 5 $listtemp='<li><a href="[!--titleurl--]"><img src="[!--titlepic--]">a>li>';
Explanation: $r[titlepic] is the title picture field variable. $listtemp is the template content variable.
Example 2: If the information is released today, display the "NEW" image logo.
1$newimg=''; 2 if(time()-$r[newstime]<=1*24*3600) 3{ 4 $newimg='<img src="NEW图片地址" border="0">'; 5} 6 $listtemp='<li><a href="[!--titleurl--]">[!--title--]a> '.$newimg.'li>';
Explanation: $r[newstime] is the release time field variable. $listtemp is the template content variable.
Example 3: Call the company name of the submitting user.
1$userr=$empire->fetch1("select company from {$dbtbpre}enewsmemberadd where userid='$r[userid]' limit 1"); 2 $listtemp='<li><a href="[!--titleurl--]">[!--title--]a><span>公司名称:'.$userr[company].'span>li>';
Description: $r[userid] is the publisher user ID field variable. $listtemp is the template content variable.
Other instructions:
If $listtemp refers to the template content using single quotes, then the single quotes must be added in front of it, for example: $listtemp='e2bc8e0df8ee9ae5086eb844173c87fa' ;
On the contrary, if you use double quotes to quote the template content, you must also add double quotes before the double quotes, for example: $listtemp="4802e4e9fee0dce56d39093587a29fe0";
Support program The code can implement many very complex application requirements.
The above introduces the Empire CMS list template listvar support program code, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.