lightbringer
lightbringer

Reputation: 835

Phalcon volt include another volt

so I have this volt code:

views/administrator/index.volt

{{ content() }}
{% set user = session.get('user') %}

<br />
<div class="row">
    <div class="col-xs-12 col-md-12 col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
            <a data-toggle="collapse" href="#container_userForm">
                <span class="glyphicon glyphicon-asterisk"></span>
                <b style="color: green;">New user</b>
            </a>
        </div>
        <div id="container_userForm" class="panel-collapse collapse">
            <div class="panel-body">
                {% include "administrator/" ~ user['role'] ~ "-form-user.volt" %}
            </div>      <!-- end panel body -->
        </div>
    </div>
    </div>
</div> <!-- end row -->

views/administrator/moderator-form-user.volt exist and has some content.

but when I run the code, I have this error

View '/var/www/html/phalcon-dash/app/config/../../app/views/administrator/moderator-form-user.volt' was not found in the views directory

I took out the user['role'] and use {% include "administrator/moderator-form-user.volt" %}, it works normally (user['role'] = 'moderator')

can anyone explain to me why it happens and how to work around it, I'll need to implement more roles in the future, and I don't want to have multiple if-else in volt

Update

This is the answer to the problem

Volt not including file if path is concatenated

Upvotes: 2

Views: 3199

Answers (2)

CHE6yp
CHE6yp

Reputation: 86

Try to use the slash. Your include probably looks for a folder "administrator" inside of a folder "administrator", where index.volt is.

{% include "/administrator/" ~ user['role'] ~ "-form-user.volt" %}

Upvotes: 0

Ilgıt Yıldırım
Ilgıt Yıldırım

Reputation: 443

Have you tried it with partial? {{ partial("administrator/" ~ user['role'] ~ "-form-user") }}

I'm guessing something is not right with views directory. Could you check it out as well?

From your controller, you can try this to get your views directory; $this->view->getViewsDir()

Upvotes: 1

Related Questions