Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel + Twig + Asset
  • Hello guys, I had one problem. I´ve install Fuelphp and I want use twig. But I can't include js or css file in twig page. Like:

    Controller:
    public function action_twig()
        {
            //passing data to the view
            $data = array();
            $data['title'] = "I am cool right ? :)";
            $data['body'] = 'Yes, Because The script is Running :)';

            return Response::forge(View::forge('welcome/test.twig',$data));

        }

    My twig page:

    <!doctype html>
    <html>
    <head>
    {{asset_js('bootstrap.js')}}
        <title>{{ title }}</title>
    </head>
    <body>
    {{ body }}
    </body>
    </html>

    I´ve try with casset... but all of these include the string "<script src='.../bootstrap.js'></script>" or include like this: <script src="<script src="../bootstrap.js"></script>"></script>

    Someone with same problem?

    Please help-me.
  • HarroHarro
    Accepted Answer
    The Fuel Asset class doesn't generate relative links using dots, unless you have configured your base_url in the config as being "../".

    Also check your asset configuration file, to make sure it correctly points to your asset folder.

    You can test it in your controller using

    \Debug::dump(\Asset::js('bootstrap.js'));
  • You didn't understand. The url is fine. If I copy and paste in URL it´s work. My problem is: don´t include the tag script, its print the string. Like string. 

    Thanks.
  • And this debug, return a string... :-O
  • Like this:
     Variable #1:
      (String): "	<script type="text/javascript" src="http://local.testes.intranet.ice/fuelphp/public/assets/js/bootstrap.js?1378650320"></script>
    "
    (131 characters)
  • Ah, you have the logic in the controller, and you pass that on to the View?

    I don't know twig, but I assume that it encodes return values of functions if you get the literal string in your output. I don't know twig, I've never used it, so I can not comment on that.

    edit: I've quickly scanned the twig docs. It could be that you have an autofilter enabled that escape all values returned by a function.
  • it's look you have read article at http://indoallcode.com/install-twig-on-fuelphp

    I think this problem about autoescape, it's look autoescape on when you try to pass {{asset_js('bootstrap.js')}} 

    you can change to html response by adding raw filter
    {{asset_js('bootstrap.js') | raw }}


Howdy, Stranger!

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

In this Discussion