Is it possible to render custom view (just custom .phtml) template with Phalcon\Mvc\View?

avasin picture avasin · Jan 14, 2013 · Viewed 9.8k times · Source

I need to render email templates in variable to send them later (which are stored in .phtml files), and i really don't want to implement my special class for handling this.

Is it possible to render not controller action view, but custom one?

I tried following code, but it outputs NULL :((

// Controller context
$view = new Phalcon\Mvc\View();
$view->setViewsDir('app/views/');
$view->setVar('var1', 'var2');
// Setting some vars...
$view->start();
$view->partial($emailTemplatePath);
$view->finish();
$result = $view->getContent();
var_dump($result); // Gives null

Answer

twistedxtra picture twistedxtra · Jan 15, 2013

In addition to the response by Nikolaos, you can use $view->getRender() to render a single view returning its output.

$view->setViewsDir('apps/views/');
echo $view->getRender('partials', 'test'); // get apps/views/partials/test.phtml