Volt not including file if path is concatenated

时光怂恿深爱的人放手 提交于 2019-12-07 18:41:25

问题


I'm trying to iterate through a Model collection in volt:

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

The type can be text or images. If i use the above code, i get the error:

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

I'm sure that the file exists, since if i changethe include, it'll work:

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

It'll also fail on:

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

What is the reason that the first version is producing that error? ( I know i could just use ifs.. But theres quite a list of element types later on. )


回答1:


This will not work.

To include view dynamically use partial:

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

There is no '.volt' since partial will add it.



来源:https://stackoverflow.com/questions/27039618/volt-not-including-file-if-path-is-concatenated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!