Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to render image when asset autorender is false?
  • I set in asset.php config 'autorender' => false (it's suitable for me in most cases).

    But I encountered with problem. When I do this <?=\Asset::img('/path/to/img')?> in my view, I have the error: "Asset_instance could not be converted to string".

    Is there a way to render image with Asset class in this mode (autorender => false)?
  • HarroHarro
    Accepted Answer
    You can not render an individual asset instance by default if you don't auto-render, that is what that setting controls. So if you switch it off...

    You can work around it by using some dummy group:

    echo Asset::img('some.png', array(), $rg = uniqid())->render($rg);
  • I've solved this problem otherwise. Extend and replace Asset_Instance for make his img method always rendering when it does not use the groups. I think this behavior is preferential.
  • Well, this is the downside of disabling auto-render. If you want auto rendering, don't disable it.

    For css and js you would always want to use  a group, as they are usually rendered in one place (for css) or two places (for js).
  • >>If you want auto rendering, don't disable it.

    In fact, I didn't want to disable auto rendering, but I wanted to cut notation of this:
    \Asset::forge()->js(array(...), array(), '_default_')->css(array(...), array(), '_default_');

    to this:
    \Asset::forge(()->js(array(...))->css(array(...));
  • HarroHarro
    Accepted Answer
    Unless you're hardcoding your pages, normally you would always use a group. We use two for css ('header-first' and 'header-last') and four for js (header and footer, and for both first and last).

    And they are rendered in our page template, first before last (so you can control the fact that some js files need to be loaded before others, like jquery of bootstrap files).

Howdy, Stranger!

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

In this Discussion