0

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.

2 Answers2

0

You can use set_global on your view, and then the exposed variable will be available everywhere.

$view->set_global('some_data', $some_data);
// instead of
$view->some_data = $some_data;

Also, when using set_partial, you can specify a View instance instead of the path for the view. That way you can pass variables directly into the View instance specified to set_partial. Though I'm not sure it solves your problem. Still, here's an example:

$view = View::forge('nav/search');
$view->some_data = $some_data;
$theme->set_partial('top_nav_search', $view);

Edit: I wrote View::forge, but more appropriate would've been to write $theme->view in this example. Like this:

$view = $theme->view('nav/search');
$view->some_data = $some_data;
$theme->set_partial('top_nav_search', $view);
Tamás Barta
  • 1,617
  • 1
  • 19
  • 23
  • Keep in mind that using `set_global` adds overhead as the global data is copied between views with the current implementation. – Emlyn Sep 23 '14 at 14:28
  • @AshiqueZakariyyaP What do you mean by APP/View? `Theme::view()` (or `$theme->view()`, since it's not static, I guess) has a very similar signature compared to `View::forge()`, you can use that as well in the second example. Do you mean that does not work? @Uru I didn't know that, that sounds terrible :D – Tamás Barta Sep 24 '14 at 09:39
0

Answer Found:

using View Class will not work with theme. It will search for APP/View folder.

we have to use

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

found working

  • It's actually the same that I wrote in my second comment to complement my answer to avoid a misunderstanding. `Theme::instance()->view()` actually returns a `View` class. I actually made the mistake to write `View::forge()` instead of `$theme->view()`, but I thought you'll figure out, since you are working with the `Theme` class. I didn't know you didn't use `set_partial()`, but echo a `View`, which removes a layer of flexibility, but might work better for you. I'll edit my answer to correct this mistake. – Tamás Barta Sep 30 '14 at 08:37