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.

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



30.9k
Accepted
answer

Hi

It is possible. If you define function via php http://docs.phalconphp.com/en/1.2.6/reference/volt.html#id3



20.3k

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.