Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
View blocks buffering similar to CakePHP's blocks?
  • In CakePHP I can buffer content and fetch it later using an identifier:
    for example, in a view, I can have something like

    $this->append('myblock'); // start buffering for block `myblock`
    // content here will be buffered
    $this->end();

    then in the template, i can have
    echo $this->fetch('myblock');// This will output the buffered content


    My use case for this is for putting inline javascript in views at the bottom of the template.

    Is there something similar to this in FuelPHP?
  • In FuelPHP that is not needed.

    You can use Asset::js() to add your javascript to an asset group, and then at the bottom of the template call Asset::render() on that group with 'true' as second parameter, indicating the group contains raw code that needs to be rendered inline.
  • As far as I know, Asset::js only accepts files.

    I have views that have js code only applicable to them and unusable anywhere else, that's why I write javascript inline with the view. Having to put them into a separate file will only add to the clutter.

    My workflow with Cake is to collect these inline javascript code via buffering (blocks), minify them, and render them at the bottom of the template.

    Is it possible to add this feature with FuelPHP, or is there a workaround?
  • You are right.

    Can you create a feature request for this at https://github.com/fuel/core/issues with a use case?
  • Leave it, no longer needed, I've added the feature to 1.7/develop, for both css and js.

    See http://fuelphp.com/dev-docs/classes/asset/usage.html for examples.

Howdy, Stranger!

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

In this Discussion