Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Asset::render('something') always return empty
  • No matter how many files set to the group, it always return empty.

    I tried to debug the code and found that:
    //file: fuel/core/classes/asset/instance.php
    //method: public function render($group = null, $raw = false)
    //Line: 225

    is_array($group) or $group = array();

    Because the $group is defined as a empty array, the foreach afterward will always skip!

    I believe it should be:

    is_array($group) or $group = array( $group );

  • Sounds logical, but that would mean that

    echo Asset::render('header');
    would never work. And it works fine here, I use that on a daily basis. Looking deeper into the code, you'll that before it gets to this line, it fetches information from an internal array if $group is a string. And that returns an array.

    So you only get to this line with $group NOT being an array is if you try to render a group that doesn't exist. In which case array() is fine, because there is nothing to render.
  • I tried go through the code "line by line" again. I found that template file is processed before any other views file.

    I put the css file in view:
    Asset::css('partial.css', array(), 'head');

    but it will never render because the views file is rendered after the template file.
    If like that where should I put the line of code above?
  • Ah, you've been caught by lazy rendering!

    If you have build your own templating system using plain views, you have the problem that parent views are always rendered before child views. Quite logical if you think about it, it doesn't know the variable you echo in your template is a View object until it gets there.

    There are two ways to fix this:
    - use the Theme class. It was designed for partial support, and doesn't have this issue
    - render them manually before you pass them to the template (don't forget to disable encoding if you do!)

Howdy, Stranger!

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

In this Discussion