Hello,
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:
en\activate.php
$messages = array(
    'greetings'     => 'Dear {{ user_name }}',
    'introduction'  => 'An account has been created at {{ site_name }}.',
);activate.volt
<td>
    <p>{{ greetings }},</p>
    <p></p>
    <p>{{ introduction }}.</p>
    <p></p>
</td>controller
$di = $this->getDI();
$this->view = new Phalcon\Mvc\View\Simple($di);
$this->view->setViewsDir('/views/');
$this->view->registerEngines([
    '.volt' => function($view, $di) {
        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
        $cachePath = $this->path . 'cache/';
        $volt->setOptions([
            'compiledPath' => $cachePath,
            'compiledSeparator' => '_',
            'compileAlways' => true
        ]);
        return $volt;
    }
]);
require $l10nFile =  'messages/en/activate.php';
// loads the $message array with all the translations
$this->view->setVar('user_name','Human');
$this->view->setVar('site_name','www.example.com');
$content = $this->view->Render('activate.volt', $messages);This is what I am getting:
<td>
    <p>Dear {{ user_name }},</p>
    <p></p>
    <p>An account has been created at {{ site_name }}.</p>
    <p></p>
</td>But this is what I want to get:
<td>
    <p>Dear Human,</p>
    <p></p>
    <p>An account has been created at www.example.com.</p>
    <p></p>
</td>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.