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

How to render a partial view that deals with its own controller within another view?

I have 2 volt.

/view
    /index
        /index.volt
    /shared
        /left_menu.volt //there is some variable should render by SharedController.php

file: index.volt like this:

{{ partial("shared/left_menu") }}

And file: left_menu.volt like this:

{{ test }} 

SharedController.php:

...
something
...
$this->view->setVar('test', 'why!!!!!!');
...

When I visit the indexController, I got this Notice Error:

Notice: Undefined variable: test in C:\XXXX\app\cache\c__XXXX_app_views_shared_left_menu.volt.php on line 36

Why? and How could I do?

to render a partial view that deals with its own controller?

could you help me? thx.bro.^_^



4.0k

Manual

{{ partial("shared/left_menu", ['test': test]) }}


875

Manual

{{ partial("shared/left_menu", ['test': test]) }}

thx,but you meens that I could only set a variable named test in IndexController ?

But I want {{ test }} in the left_menu.volt replaced by the variable of SharedController.

Manual

{{ partial("shared/left_menu", ['test': test]) }}

You don't need to pass variables to a partial. Partials are supposed to inherit variables.