translations + setVar on volt template


I have an API that has no views, but I need to send mails from some classes. The mail can be sent in different languages, and I also need to replace strings on the template after I have replaced all the language strings.

Adding bits of code to show what I am doing:


$messages = array(
    'greetings'     => 'Dear {{ user_name }}',
    'introduction'    => 'An account has been created at {{ site_name }}.',


    <p>{{ greetings }},</p>
    <p>{{ introduction }}.</p>


$di = $this->getDI();
$this->view = new Phalcon\Mvc\View\Simple($di);
    '.volt' => function($view, $di) {
        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
        $cachePath = $this->path . 'cache/';
            'compiledPath' => $cachePath,
            'compiledSeparator' => '_',
            'compileAlways' => true

        return $volt;

require $l10nFile =  'messages/en/activate.php';
// loads the $message array with all the translations
$content = $this->view->Render('activate.volt', $messages);

This is what I am getting:

    <p>Dear {{ user_name }},</p>
    <p>An account has been created at {{ site_name }}.</p>

But this is what I want to get:

    <p>Dear Human,</p>
    <p>An account has been created at</p>

So, how can I achieve this? maybe the whole approach is wrong. Any ideas?

Note: It's important to mention that I don't have any views registered in the DI object, I am instancing the view only when I need it, so I don't want to have objects in memory that I will use only a few times.

edited Feb '16

P.S. Currently, to achieve this I am doing something like this:

$content = str_replace("{{ user_name }}", "Human", $content);

But I want a cleaner solution.

edited Feb '16

Hello, i can't remember in which project i was in your exact situation.

Please read this section "Hierarchical Rendering" (second example) here:

I remember i played with those variables:

Will get back to you with example if i manage to remember where i used it.

Example as promised!

In this project i needed to render image editing popup with ajax:

        $response = new \stdClass(); 
        $response->html = $this->view->getRender('templates', 'editThumbnailsPopup', $viewParams, function($view) {