DedeCms Runphp 标签中调用其他变量的方法
我们都知道,在DedeCMS中是可以使用PHP的,常见的方法就是if else了,例如模板制作中,我们需要对来源和作者进行判断,如果为空,则提示:暂无或不详,样例:
1 |
{dede:field name= 'source' runphp= 'yes' } |
2 |
if (@me == "" ) @me = "" ; else @me = "来源:" .@me; |
|
但是如果想在上边的代码中调用其他变量,怎么调用呢?今天织梦58小编就遇到这个问题,在织梦官方论坛查找了一下,现在将方法公布如下,我们将变量写为通用:array,代码如下:
1 |
{dede:field name= 'array' runphp= 'yes' } |
3 |
if (@me[ 'source' ] == "" ) @me = "@me['其它变量']" ; else @me = "来源:" .@me[ 'source' ]; |
|
还有一种办法如下:用全局变量来解决这个问题:
1 |
{dede:php}$GLOBALS[ 'xxoo' ]=$arc->Fields[ 'fieldname' ]{/dede:php} |
3 |
{dede:field.xxxx runphp= "yes" }@me= "test" .@me. "-test" .$GLOBALS[ 'xxoo' ];{/dede:field.xxxx} |
|
即,先开一个PHP的标签,把想赋的值替换给global变量。然后在另外的运行中将field值赋值给他。