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

Accessing object methods from inside Volt templates

Hey,

I'm trying to provide access to \Phalcon\Translate\Adapter\NativeArray on a global scale by setting it as a view var in my controller:

<?php
$mainTranslate = new \Phalcon\Translate\Adapter\NativeArray(array('content' => $messages));
$this->view->setVar('t', $mainTranslate);

However, from inside the Volt template, I can not access the method of t as it should work (in case I understood the docs right):

<title>{{ t._('Hi') }}</title>

All I get is the following error:

Parsing error before '('Hi') }}

What am I doing wrong?

Thanks in advance!

Best,



98.9k

Hey Philipp, this is a bug affecting versions <= 0.9.1 where underscore (_) is not allowed at the beginning of an identifier, this is fixed in 1.0.0, could you try with that version?

git clone -b 1.0.0 https://github.com/phalcon/cphalcon
cd cphalcon/build && sudo ./install

Can't try it, unfortunately, as I'm using a brew recipe on OSX and fortrabbit for the web. But once you push 1.0 I'm sure I'll be able to use it, until then I'll manage ;)