Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Nested View in Theme Views using Fuelphp
  • I have working with Fuelphp and done some tiny apps, Now i am moving to bigger one, now i am stuck with this.

    I have enabled theme in fuelphp and it is working perfectly, In my App there is a Top Nav bar, In Nav bar there is 3 drop down notification system like facebook & also search option. So i have created top_nav partial. I want to make the search and notification system in partial inside partial, to making it more modular, so i created another partial of top_nav_search and top_nav_notif . Both partials need some variables to transfer from controller, How i do that. My variables are passing to top_nav only. Not top_nav_search or top_nav_notif.

    How can i add partial inside the partial.
  • What PHP version are you using?

    From PHP 5.4 onwards, you can use $this->get() to access variables inside the view. So you can get your second partial using

    echo View::forge('something')->set('var', $this->get('var'));
  • Dear,

    Found this information usefull.
    When applied, It showing error. "View not found.."

    I think it searching in APP/View folder. I want to use theme instead of APP/view. My all partials are located in 
    App/Themes/<ThemeName>/partials/level1
    App/Themes/<ThemeName>/partials/level2

    not_nav is in level1, and top_nav_notif is in level2
  • HarroHarro
    Accepted Answer
    Ah, if your View file is part of a Theme, you can not use View::forge(), you need to use

    echo Theme::instance()->view('partials/level2/top_nav_notif');

    assuming you use the default instance. If you have a named instance, you need to supply the name to instance() to load the correct one.
  • Thanks Harro, I love this Code.

    Also,

    How i pass variable with 

    echo Theme::instance()->view('partials/level2/top_nav_notif');

    Can i pass variable directly from controller like partials do?
  • HarroHarro
    Accepted Answer
    view() forges a new View object, and returns it. So you pass data any way you can pass data to  View::forge(): as an array as second parameter, using the set() method, or the set_safe() method.

    If you want to pass an individual variable (assuming a partial variable called 'var;), I suggest you use

    echo Theme::instance()->view('partials/level2/top_nav_notif')->set_safe('var', $this->get('var'));

    because the variable is already escaped (or not) when passed from your code to the theme partial, and you want to pass it on to your sub-partial without alteration. If you use set(), it will escape the data, which either causes the variable to be escaped twice, or in case you had used set_safe(), it will escape something that you don't want escaping.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion