PHP with volt

I want to use php functions like strwordcount with volt. For example, Split the output of {{ posts.postcon['postcategory'] }}, It will something like

category1 category2 category3

and create links something like

<a href="cat/category1">category1</a><br />
<a href="cat/category2">category2</a><br />
<a href="cat/category3">category3</a><br />


18.6k
edited Aug '14

Create a Component, register it in the bootstrap, and call it in the volt template like {{ myComponent.myFunction("myParam") }}. In the function, you will return a string that contains that HTML code (beware of autoescape, it will affect the returned string).

At least this is what I remember.

You can extend Volt ; see http://docs.phalconphp.com/en/latest/reference/volt.html#extending-volt

Or, if you want a quick & dirty solution: simply use PHP in your volt template with php open/close tags ; <?php $foo = "bar"; ?> will allow you to use {{ foo }} as a volt variable.