我正在使用一个名为bolt.cm的框架。一个基于silex的简单框架。有一个小枝函数来获取特定内容类型的记录:
{% setcontent products = 'products' %}要获得记录并按特定字段排序:
{% setcontent products = 'products' orderby 'datepublish' %}上面将提取按datepublish字段排序的记录。现在,我想从GET参数传递orderby字段。将GET参数存储在从控制器传递的全局twig变量中,该变量定义为sort_by变量。
{{ sort_by }}上面会将sort_by值打印到html中。在page:/products?sort_by=datepublish中,sort_by值将设置为datepublish,现在我将将该变量组合为setcontent函数,如下所述:
{% setcontent products = 'products' orderby sort_by %}现在我收到了错误:
An exception has been thrown during the compilation of a template ("Attribute "value" does not exist for Node "Twig_Node_Expression_Name".") in "products.twig".我的问题很简单,如何使sort_by在该函数中被识别为一个值?请不要让我这样做:
{% if sort_by == 'datepublish' %}
{% setcontent products = 'products' orderby 'datepublish' %}
{% elseif sort_by == 'another_field' %}
{% setcontent products = 'products' orderby 'another_field' %}
{# and so on for every single field #}
{% endif %}发布于 2014-08-13 07:15:39
你用的是哪种型号的螺栓?这应该是可能的,因为版本1.6。新闻稿上写着:
现在可以在{% setcontent %}标签中使用变量,如:{% setcontent = 'pages‘order my_var限制other_var %}。
https://stackoverflow.com/questions/22292783
复制相似问题