We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Volt, Controller and Partials

Hello,

partials/headers/logged-user.volt :

<div class="header">

      <div class="logo">...</div>

      <div class="user-menu">
              <a href="{{ User.profileUrl }}" id="user-menu-link">{{user.name}}</a>
     </div>

</div>

Now I need to call a funcion from a service, "ServerJS"

$this->ServerJS->initBehaviour('assyncPopover', array( 'id'=>"user-menu-link' ));

(This function will add a Javascript before the "body" close tag)

My problem is that partials have no controllers and I don't know where to call this function.

edited Mar '17

What you mean? Partials is just partial which you "include" in other view, you can call this function exactly in an action which will render view containg this partial.

You can also just do {{ serverJs->initBehaviour }} but i don't recommend it.

Also why you can't use phalcon assets?



1.6k

What you mean? Partials is just partial which you "include" in other view, you can call this function exactly in an action which will render view containg this partial.

You can also just do {{ serverJs->initBehaviour }} but i don't recommend it.

Also why you can't use phalcon assets?

BaseController sets headers like :

$this->view->header = $this->auth->getUser() ? "partials/headers/member" : "partials/headers/visitor";

/views/index.volt:

{% if header %}<div id="header-wrapper">{{ partial(header) }} </div> {% endif %}

Every Controller can have it's own header.


I'm using a custom AMD loader

Then i guess you can just use this dirty {{ serverJs->initBehaviour }}