如果路径已连接,则伏特不包括文件 [英] Volt not including file if path is concatenated
本文介绍了如果路径已连接,则伏特不包括文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试遍历以伏特为单位的模型集合:
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
我确定该文件存在,因为如果我更改include,它将起作用:
I'm sure that the file exists, since if i changethe include, it'll work:
{% include "partials/panels/edit-image.volt" %}
它也会失败:
{% include "partials/pandels/edit-" ~ "image.volt %}
第一个版本产生该错误的原因是什么? (我知道我可以只使用ifs..但是稍后会有很多元素类型的列表.)
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. )
推荐答案
这将不起作用.
要包含动态查看使用partial
:
{% if model.elements|length > 0 %}
{% for element in model.getElements() %}
{{ partial( "partials/panels/edit-" ~ element.getType() ) }}
{% endfor %}
{% endif %}
没有'.volt'
,因为partial
将添加它.
这篇关于如果路径已连接,则伏特不包括文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文