Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Asset class
  • Hi guys! I would like to add a javascript file in codebehind when a specific controller is called, is this possible with the asset library? I tried this but it adds the file at the very top instead of inside the <head> section.
     public function action_crop($id){
    echo Asset::js('jquery.imgareaselect.min.js');
    }
    

    I need the javascript file only for a single controller action therefore trying to avoid adding it to the tempate file. Many thanks in advance for your help.
  • Why you don't put :
    Asset::js('jquery.imgareaselect.min.js');
    

    in a view behind code?
  • The idea is that in your code, you add assets to asset groups:
    public function action_bla()
    {
        // this doesn't output anything
        Asset::js('jquery.imgareaselect.min.js', array(), 'head');
    }
    
    And then in your view, request the group
    Asset::render('head');
    

    You should not use echo or print. It will generate output on the spot, while views are rendered at the end. Also, once you start caching, you won't cache anything you echo...
  • thank you WanWizard, this is exactly what i wanted :)
  • Harro Verton wrote on Friday 13th of May 2011:
    And then in your view, request the group
    Asset::render('head');
    

    You should not use echo or print. It will generate output on the spot, while views are rendered at the end. Also, once you start caching, you won't cache anything you echo...

    ok, i had to do echo in the view to get it to work, does it mean there's a bug as you said I shouldn't use echo or print?
    ecoh Asset::render('head');
    
  • I replied from memory, always check the docs ( which do say you need echo in case of render() ). ;)

Howdy, Stranger!

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

In this Discussion