Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Nesting Views
  • Is it a bad practice to use the view class directly from inside view files?

    Example:
    <!-- views/site/two_col.php -->
    <?=\View::forge('site/header')?>
    <div class="widget">
    <?=\ViewModel::forge('site/latestbands')?>
    </div>

    I don't see any problem doing this, since it works, and is specially useful with viewmodels. But I can wrong.
  • HarroHarro
    Accepted Answer
    If it works for you, then why not use it? Fuel doesn't want to be restrictive in any way.

    Only thing you have to be careful about is rendering sequence. This way, parent views are rendered before child views, which means your child views can not contain Asset calls (for example to add additional CSS to the page header).

    If you need that, you'll have to use Theme, which renders child views (partials) before parent views, before the page template.
  • Thanks a lot. And it's better than that, just tested here and Asset calls still works.
    Also, global variables set through View::set_global() are still acessible from child views. That's kinda the way I used to do when I was working with CodeIgniter.

    Fuel is awesome, I'm having a lot of fun in learning it.
  • Normal Asset calls (like for img) work, but you can't use Asset in a child view to add an additional CSS file to the page header, because by the time you get to rendering the child view, the page header is already rendered.

    Global variables are exactly that, global. So accessable from any view. Using it isn't exactly seen as best practice though, so try to avoid them if possible.

Howdy, Stranger!

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

In this Discussion