Home > php教程 > php手册 > 在自定义标签的属性里使用变量

在自定义标签的属性里使用变量

WBOY
Release: 2016-06-07 11:43:17
Original
1438 people have browsed it

用TP不久,刚使用自定义标签发现不会在属性里使用变量,看了下源码下的TagLibHtml.class.php,终于弄清楚怎么用了
<?php <br /> import('TagLib');<br> Class TagLibWx extends TagLib{<br>     Protected $tags = array(<br>         'wxtype' => array(<br>             'attr' => 'value',<br>             'close' => 0,<br>             )<br>         );<br>     <br>     //eg:<wxtype></wxtype><br>     Public function _wxtype($attr){<br>         $attr = $this->parseXmlAttr($attr);<br>         $value = $attr['value'];<br>                 $parseStr = '非服务';<br>         if(!empty($value)){<br>             $parseStr = '<?php if(&#039;.$value.&#039; == \&#039;service\&#039;){ echo \&#039;服务\&#039;; }else{ echo \&#039;非服务\&#039;;} ?>';<br>         }<br>         <br>         return $parseStr;<br>     }<br> }假如在模板里有一个数组变量wx,在模板里可以这么写:<wxtype></wxtype>其实原理很简单:就是在TagLibWx.class.php里对应的方法里输出php代码到模板页面,相当于在模板里写了一段Php代码

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template