织梦CMS模板中dede标签使用php和if判断语句的方法

2017-04-13 21:01:34 dedecms

今天我们来说说

织梦

模板中dede标签使用php和if判断语句的方法:

  先来看看下面这个标签:   {dede:field.tong_gg php=yes} if(@me==""||empty(@me)) @me="<p>无</p>"; {/dede:field.tong_gg} 注释: @me:就是当前字段的值,你可以在if中给其赋值,然后判断结束后它的值就变成你赋的值,打印出来   下面来说说具体的方法:   方法一:   用个if判断语句,判断一个字段是否有东西,有就输出1,没有则就出2,   下面是的代码加载内容页模板中   {dede:field.audio runphp='yes'} if(@me<>'')@me="如果audio字段里有东西就输出这个,支持html代码,并且可以在代码中使用@me来调用audio字   段值,但是不要有双引号。"; else @me="如果audio字段里没有东西就输出这个,也是支持html代码,并且也是可以在代码中使用@me来调用audio字   段值,也是不要有双引号。"; {/dede:field.audio}   audio是自己添加的一个字段   方法二:   给DEDE模板加了新功能 if判断功能 标签iif和elserun   增加了变量$str和$str_count $str是最终显示的内容 $str_count是循环显示内容的条数。   增加了标签iif 和 elserun 满足iif的条件就正常运行 如果不满iif的条件就运行elserun  如果不满足iif的条件,也没指定elserun就返回空白   iif和elserun都是正常的php语法.   {dede:arclist orderby='click' titlelen='30' row='10' iif="$str_count>1" elserun="$str=暂时没有内   容"} <li><span class="gptlink">[field:textlink/]</span></li> {/dede:arclist} 运行结果 如果arclist没返回结果就显示 暂时没内容 <title>{dede:global name='cfg_webname' iif="strlen($str)>10" elserun="$str.='我的网站'"/} </title> 运行结果 如果cfg_webname长度大于10就正常显示 否则就在标题后面增加我的网站 显示 更改方法 只更改一个文件就是/dede/include/pub_dedetag.php 一、搜索 foreach($GLOBALS[$arr] as $k=>$v){ 更改成 $GLOBALS['autoindex']=0; foreach($GLOBALS[$arr] as $k=>$v){ $GLOBALS['autoindex']++; 二、搜索 $this->CTags[$i]->TagValue = $DedeMeValue; } 在后面加上 $str = $this->CTags[$i]->TagValue; $str_count = $GLOBALS['autoindex']; if( $this->CTags[$i]->GetAtt("iif")!="" ){ if(! eval("return {$this->CTags[$i]->GetAtt('iif')} ;" )){ if($this->CTags[$i]->GetAtt("elserun")) { $this->CTags[$i]->TagValue=eval("return {$this->CTags[$i]->GetAtt('elserun')} ;" ); }else{ $this->CTags[$i]->TagValue=''; } } }   OK咯!就说到这里了啊!