在expressionengine中设置自定义模板变量

时间:2011-09-25 23:42:38

标签: expressionengine

我需要在条目模板中输入几次条目。

所以我想从下面得到输出并分配给一个变量,这样我就可以在模板中重用:

{exp:channel:entries channel="product" limit="1" status="open"}
    {categories}{category_name}{/categories}
{/exp:channel:entries}"

它是如何做到的?

3 个答案:

答案 0 :(得分:9)

现在,您可以启用模板以允许PHP,然后您可以编写如下内容:

{exp:channel:entries channel="product" limit="1" status="open"}
    {categories}
        <?php $category = '{category_name}'; ?>
    {/categories}
{/exp:channel:entries}

然后你将{category_name}存储在php-variable“category”中。稍后您可以按照自己的意愿重复使用它,如回应它:

<?php echo $category; ?>

您甚至可以将其与其他EE标签进行比较:

{exp:channel:entries channel="product" limit="1" status="open"}
    {if <?php $echo($category) ?> == title}
        This title have got the same value as the category!
    {/if}
{/exp:channel:entries}

答案 1 :(得分:3)

克罗克斯顿的Stash:http://devot-ee.com/add-ons/stash与NSM Transplant(上面的Derek提到的)几乎完全相同,并且是免费的。其中一个插件肯定是做你想做的最简单的方法。

答案 2 :(得分:2)

EE没有内置的方法来保存标记循环中的数据,并在该标记循环之外的模板中的其他地方重用它。

一种解决方案是使用NSM Transplant来完成你想要做的事情。

另一种方法是将整个条目页包装在channel:entries标记中,这样您就可以在任何需要的地方使用categories循环,然后使用嵌入来嵌入任何无法嵌套的内容channel:entries