We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Volt link_to with translation

Hi to all. My problem is a syntax problem.

I want include translation function in tag Volt "linkto" between <a> </a> php results.

With this syntaxt:

<li> {{ linkto("Alumnos/index", "<i class='glyphicon glyphicon-user')></i>") }} {{mt.('Alumnes')}}</li>

the result translation is put out of <a> </a>:

<li> <a href="/escuelaProyecto/Alumnos/index"><i class='glyphicon glyphicon-user')></i></a> Alumnos</li>

And i want the next result:

<li> <a href="/escuelaProyecto/Alumnos/index"><i class='glyphicon glyphicon-user')></i> Alumnos</a> </li>

How can I do it, or what is the correct syntax? Thanks everybody.

edited May '18

An alternative is no use Volt Tag, but out of curiosity I want to know how it is in Volt. Regards


$msg = $mt->_("Alumnes");

echo "<li> <a href='/escuelaProyecto/Alumnos/index'> <i class='glyphicon glyphicon-user')> </i> " . $msg . " </a></li>";




try with:

<li> {{ link_to("Alumnos/index", "<i class='glyphicon glyphicon-user')></i>" ~ mt.('Alumnes') ) }}</li>

Thanks, but it report this syntax error:

Parse error: syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\escuelaProyecto\cache\c__xampp_htdocs_escuelaproyecto_app_views_index.volt.php on line 125


<li> {{ link_to("Alumnos/index", "<i class='glyphicon glyphicon-user')></i>" ~ mt('Alumnes') ) }}</li>

Thanks again, i am try very combinations syntax, but the last porposal, it report: Macro 'mt' does not exist

Anyway, it does not matter. I do it with pure php and solved. Thank you


<li> {{ linkto("Alumnos/index", "<i class='glyphicon glyphicon-user')></i>" ~ mt.('Alumnes') ) }}</li>

hope this work, this is my last try, hahaha ;-)

Hahahaha, after weekend, No, sorry.

Parse error: syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\escuelaProyecto\cache\c__xampp_htdocs_escuelaproyecto_app_views_alumnos_index.volt.php on line 34

Don`t worry, I do it with pure php and solved. Thank you

edited May '18

And can you post how this code looks like in this php file on this line(like in generated template)? This code most likely should work, im not sure only about mt.. Why this dot? You need to use it as mt('Alumnes') and either add such macro or function to volt, that's why you had error Macro 'mt' does not exist because it's not added as macro or function.

edited May '18

Thanks Slawski, in first time i'm beginner at Phalcon, but 'mt' is a variable declarated at ControllerBase:

public function loadMainTrans()


   $translationPath = $this->_getTransPath();

   require $translationPath.".php";

   //Return a translation object

   $mainTranslate = new Phalcon\Translate\Adapter\NativeArray(array("content" => $mensajes));

   //Set $mt as main translation object

   $this->view->setVar("mt", $mainTranslate);


How can I add as macro or function??

edited May '18

Yea but it's an object and you don't all any method. And NativeArray doesn't really implement __invoke method anyway. So you should call it like mt._ or mt.t

Well you don't even need to add it as variable/macro/function. You can register it as a service and it will be available in view.

// Add it to your di:

$di->set('mt', new Phalcon\Translate\Adapter\NativeArray(array("content" => $mensajes));

And then just call like mt._("Something") or mt.t("Something"). If you want to really call it as a function, then you need to write your own class which will implement __invoke method.

Also why you even use things like require? There is $loader->registerFiles()

Ok, I'll try your example like service. I use the 'require' because I'm follow examples from github, manuals, this forum, etc.

Then those examples are old most likely.

certainly, see you