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

Creating an array in Volt from another object

Hi there,

I can see in the Volt documentation that you can create different kinds of array literals and manually specify their value(s).

I'd like to build a select list based on values in a complex, iterable object that can be passed in as a view variable. However, I would need to iterate over the object and then create suitable array structures that are compatible with select_static.

It doesn't look like this is possible but if anyone can confirm, I'd appreciate it :)

Thanks



58.4k
Accepted
answer

Hi

It is possible. If you define function via php https://docs.phalcon.io/en/1.2.6/reference/volt.html#id3



38.8k

Cool - thanks Duy. I hadn't thought of this and it will do exactly what I want to do which is to take a more complex object from a non-Phalcon system and allow me to select the just the data I want to form an array :)

Volt templates can also contain raw PHP if necessary.