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

Dynamic link_to content

So let's say that I have a volt page like this:

{{ link_to("index/somepage",'<span class="glyphicon someglyph"></span> MyLink ',"class":"btn btn-default") }}

I want to make the text in the second parameter - the text of the link - to be dynamic. So lets say inside the controller here I have something like $this->view->somevar = "test"; then what I want to do inside the volt is:

{{ link_to("index/somepage",'<span class="glyphicon someglyph"></span> MyLink {{somevar}}',"class":"btn btn-default") }}

Is there any way to accomplish this?



77.7k
Accepted
answer

You can concatenate strings inside Volt with the ~ operator:

{{ link_to("index/somepage",'<span class="glyphicon someglyph"></span> MyLink '~somevar~'',"class":"btn btn-default") }}