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

How to pass a a view (file volt) to variable

How to pass a view file to an variable? Example: // emails/test.volt $htmlEmail = $this->view("emails/test");

echo $htmlEmail;

Response:

<H1>Hola enviando mensaje</H1>

Help?

if anyone has this problem too... i have the solution:

return $this->view->getRender('emails', $name, $params, function($view) {
                $view->setRenderLevel(View::LEVEL_LAYOUT);
            });

where emails is the folders that contain templates, $name is the name of the template for attach and any $params to pass to the template

in this case i use this function to pass the view how template for email (swiftmailer)

    $mailer->subject(_('Ha ocurrido un error en el sistema'))
                ->to($support_email_contacts)
                ->message($mailer->template('senderror', array(
                            'siteName' => $this->config->client->siteName
                        ))
                )->from(array($contact_email => $contact_company))->send(FALSE);

;)