Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



35.8k
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") }}