The CMS list template list. var supports program code, cmslist. var
1. When adding a template, select the "use program code" option for the list. var template.
2. directly add PHP code without adding <? And?> Program start and end tags.
3. The field value array variable is $ r, and the corresponding field variable is $ r [field name]. For example, the title field variable is $ r [title]. The variable number is $ no.
4. Assign the final template content to the $ listtemp variable.
List. var template example:
Example 1: If the title image is not set, the specified image is displayed.
1 if(empty($r[titlepic]))2 {3 $r[titlepic]='/images/img.gif';4 }5 $listtemp='<li><a href="[!--titleurl--]"></a></li>';
Note: $ r [titlepic] is the title image field variable. $ Listtemp is the template content variable.
Example 2: if the message is published today, the "NEW" image ID is displayed.
1 $ newimg = ''; 2 if (time ()-$ r [newstime] <= 1x24x3600) 3 {4 $ newimg = ' '; 5} 6 $ listtemp = '<li> <a href = "[! -- Titleurl --] "> [! -- Title --] </a> '. $ newimg.' </li> ';
Note: $ r [newstime] is the release time field variable. $ Listtemp is the template content variable.
Example 3: Call the company name of the contributor.
1 $ userr = $ empire-> fettings ("select company from {$ dbtbpre} enewsmemberadd where userid = '$ r [userid] 'limit 1 "); 2 $ listtemp = '<li> <a href = "[! -- Titleurl --] "> [! -- Title --] </a> <span> company Name: '. $ userr [company].' </span> </li> ';
Description: $ r [userid] is the publisher's user ID field variable. $ Listtemp is the template content variable.
Other Instructions:
If the content of the $ listtemp reference template is in single quotes, add \ before the single quotes. For example: $ listtemp = ' ';
On the contrary, if the content of the referenced template uses double quotation marks, add \ before the double quotation marks, for example, $ listtemp = " ";
Supporting program code can meet many very complex application requirements.