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

[SOLVED] How to 'explode' in Volt?

Dear experts,

Is there any way to 'explode' in Volt? I want to create array from a string. For example:

{% set arr = explode(mystrings, ',') %}

I saw join but not the opposite.

Thanks a lot.

Jim

Hi Jim,

I think you need to prepare your data in a controller or a model and then pass already "exploded" string into volt template. Or you can extend Volt engine as described here: https://docs.phalcon.io/en/latest/reference/volt.html#extending-volt



21.5k
Accepted
answer
edited Oct '14

Hello Eugene,

Thank you for your suggestion. I'll dig up deeper into it.

I ended with this solution:

<td>                    
<?php $ids = explode(',', $doc->ids) ?>
{% for id in ids %}
<p>Row-{{ id }}</p>
{% endfor %}
</td>

Jim