We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Rendering external partial?

Hello Everyone,

Is there a way, to render a view component, that is not within the views dir., without changing it. For instance - To be able to render partial, that is located in another module.

And again, changing the views dir, or render partial whose include the partial from another place, is not a clean solution.

And if is not, it will be very nice to be able to do so :).


This may be of some help to you: https://docs.phalcon.io/en/latest/reference/views.html#stand-alone-component

I don't have a ton of experience using phalcon views, but it seems that the need to call ->setViewsDir() before running your views could complicate having your views in modular directories. It seems that you could have some luck using views as a stand-alone, where you declare a new instance of \Phalcon\Mvc\View into a variable, then set the directory locally, and finally load/render your views from that directory. The best way I could think to do that would be to either add it to a base controller or an app component/library.

If you have any code you're currently working on, please post it.


tiny modification

in your controller

$view = clone $this->view;
$view->setViewsDir(); // put here your dir
$view->render('emails', 'signup-html');
$content = $view->getContent();

echo $content;