【问题标题】:Volt not including file if path is concatenated如果路径连接,Volt 不包括文件
【发布时间】:2014-11-20 12:26:27
【问题描述】:

我正在尝试以伏特遍历模型集合:

{% if model.elements|length > 0 %}
    {% for element in model.getElements() %}
        {% include "partials/panels/edit-" ~ element.getType() ~ ".volt" %}
    {% endfor %}
{% endif %}

类型可以是文本或图像。如果我使用上面的代码,我会得到错误:

View '/path/to/phalcon/apps/frontend/views/partials/panels/edit-image.volt' was not found in the views directory

我确定该文件存在,因为如果我更改包含,它将起作用:

{% include "partials/panels/edit-image.volt" %}

它也会失败:

{% include "partials/pandels/edit-" ~ "image.volt %} 

第一个版本产生该错误的原因是什么? (我知道我可以只使用 ifs.. 但是稍后会有相当多的元素类型列表。)

【问题讨论】:

    标签: phalcon volt


    【解决方案1】:

    这行不通。

    要包含view dynamically,请使用partial

    {% if model.elements|length > 0 %}
        {% for element in model.getElements() %}
            {{ partial( "partials/panels/edit-" ~ element.getType() ) }}
        {% endfor %}
    {% endif %}
    

    没有'.volt',因为partial 会添加它。

    【讨论】:

    • 现在可以使用了,谢谢。它甚至在文档中正确说明。我只是没有注意到之前部分和包含之间的区别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2019-10-02
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多