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

VOLT

I wish to pass multiple variables for different page parts to a volt template. Being new to this, I want to make sure I handle it the preferred way.

Some example page elements:

page header (title)

body text (story)

media image (image_1)

some other element (misc_1)

Some may be able to be grouped by a query (ex: tltle/story), but others are not directly related via a query result set.

What is the best approach to this?

Many thanks!



11.6k
Accepted
answer
edited Jul '15

in your controller: $this->view->myVar = $myVar, then in in volt file, then you can access them like {{ myVar }}

if $myVar is i.e. an associative array {{ myVar.keyName }} (I suppose it's what you mean when you say 'grouped by a query', not sure...

about image, you do not pass the image as it, but rather an url pointing to it (a string so)

Thank you! It amazes me how much Phalcon is like something I was tinkering with in PHP over the past year. Love Phalcon!!