phpcms v9 如何实现标签的嵌套
在此文件里/phpcms/lib/classes/template_cache.class.php 里的 template_parse 方法里,添加如下代码
$str = preg_replace ( "/\{loop(\S+)\s+(\S+)\s+(\S+)\}/",
"<?php \$n\\1=1;if(is_array(\\2)) foreach(\\2 AS \\3) { ?>", $str
);
$str = preg_replace (
"/\{loop(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\}/", "<?php \$n\\1=1;
if(is_array(\\2)) foreach(\\2 AS \\3 => \\4) { ?>", $str );
$str = preg_replace ( "/\{\/loop(\S+)\}/", "<?php \$n\\1++;}unset(\$n\\1); ?>", $str );
前台调用方法如下:
{pc:content action="category" catid="0" num="60" siteid="$siteid" order="listorder ASC"}
{loop $data $r}
<dd> <a href="{$r[url]}">{$r[catname]}</a>
<ul class="list_ul clearfix">
{pc:content action="category"
catid="$r['catid']" num="60" siteid="$siteid" order="listorder ASC"
return="data2"}
{loop2 $data2 $v}
<li><a href="{$v[url]}">{$v[catname]}</a></li>
{/loop2}
{/pc}
</ul>
</dd>
{/loop}
{/pc}