how to define variable in phalcon php volt blade and assign data to it?

349 Views Asked by At

i have a variable in my blade that its set to the blade in controller

$this->view->->setVar("formData", $formData);

my formData is an array from my submitted form

now i want to define a new variable in? my volt blade and assign my formData to it. how should i do that?

i read phalcon(https://docs.phalcon.io/3.4/en/volt) volt document but i cant find how should i do that.

1

There are 1 best solutions below

0
Nikolaos Dimopoulos On

In your controller setVar() and setVars() can be used on the view object to set your variables and then use them in your Volt file:

$this->view->setVar('myData', $data);

and in the template

{{ myData }}

If $data is an array and you want elements from it:

{{ myData['element1'] }}

If $data is an object you can call methods on it

{{ myData.myMethod() }}

If you want to perform comparisons and assign variables in the template:

{% if myData['element'] == 'yes' %}
    {% assign reply = true %}
{% else %}
    {% assign reply = false %}
{% endif %}

References:

https://docs.phalcon.io/4.0/en/volt#variables

https://docs.phalcon.io/4.0/en/volt#assignments

https://docs.phalcon.io/4.0/en/volt#if