We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 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 :).

Thanks.

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.

Mike

tiny modification

in your controller

$view = clone $this->view;
$view->start();
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$view->setViewsDir(); // put here your dir
$view->render('emails', 'signup-html');
$view->finish();
$content = $view->getContent();

$this->view->disable();
echo $content;