jasonlewis / basset

A better asset management package for Laravel.
http://jasonlewis.me/code/basset
240 stars 76 forks source link

Using basset with TwigBridge #200

Closed pafelin closed 11 years ago

pafelin commented 11 years ago

I am using TwigBridge in my project for template engine.

From Twig Templates I can run without any problems the helper functions that you normally can call in a blade templates. For example: "config_get", "auth_check" or the last with which probably everyone are familiar "auth_check". So I define "basset_stylesheets", "basset_javascripts" and "basset_assets" to be callable in twig also. When I call for example "basset_stylesheets" I always receive an error:

Call to undefined method Basset\Environment::stylesheets()

I must say here that I have set up the package I think correct. I have all my minified files for my different enviroments, minified and generated in my folder. My question is: Can anyone confirm that I can use this package with twigBridge? And is this problem caused by not correct configuration. If someone knows how to fix it please :) I am open for suggestions

Anahkiasen commented 11 years ago

You can just do basset_show, or alias it to assets and to {{ assets('something.css') }} {{ assets('something.js') }}

pafelin commented 11 years ago

I basicly had to create a new class that will add 2 twig functions.

$this->twig->addFunction('basset_stylesheets', new \Twig_Function_Function('basset_stylesheets'));
$this->twig->addFunction('basset_javascripts', new \Twig_Function_Function('basset_javascripts'));

I didn't do it myself, a dude called "DeSmart" did it before me :)

For everyone who need to use together Basset & TwigBridge you will need to add this to your requirements:

"desmart/basset-twig-extension": "1.0.*"

So you can use both functions with no problems:

 {{ basset_stylesheets('application') }}
 {{ basset_stylesheets('application') }}
Anahkiasen commented 11 years ago

Well that doesn't feel necessary, as mentioned above you can just use Basset's show method which does the same thing, you just have to type the additional .css but that's pretty much it.

pafelin commented 11 years ago

I will try that. What I notice as a problem is that when I am using it in development env all the files are loaded separate. Which for development is fine, but when I swith to use production env than when it loads only 1 file, something wrong happens with the css. I think it switch the order of the files. Which for me is important to not do. But... I will check later.