Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

include view dynamically

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. )


Hey man

Can you used property partial is included

    {% include "partials/panels/edit-" ~ element.getType() ~ ".volt" %}

Replace to

    {{ partial( "partials/panels/edit-" ~ element.getType())  }}

Thanks, that worked. I'd still like to know "why" the first implementation did not work though. I don't see the actual difference here ..


May be this is bug, you can create issue on github:)