How to define Assetic resources in Symfony 2 yml or xml configuration file?
Asked Answered
E

2

6

Can you define assetic resource in configuration file (yml/xml)?

Lets take jquery as example. I would like to have configuration like this:

# app/config/config.yml
assetic:
  resources:
     jquery: 
        latest: "app/Resources/js/jquery-1.6.2.js"
        1_6_2: "app/Resources/js/jquery-1.6.2.js"
        1_5: "app/Resources/js/jquery-1.5.js"

And to be able to access this resource from any template in my application something like this:

{% javascripts 'jquery.latest' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

What is a proper way to do this?

And another thing. How do I reference path app/Resources/js/jquery-1.6.2.js in twig template?

{% javascripts 'app/Resources/js/jquery-1.6.2.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

This does not work. Can you do this at all? What resources I can place in app/Resources and how do I access them in my templates? Where it is documented?

Right now Symfony 2 is really lacking in documentation...

Entertainment answered 3/8, 2011 at 7:0 Comment(1)
Here you can find answer to your first question https://mcmap.net/q/1914571/-with-assetic-twig-symfony2-can-i-define-front-end-librariesBounder
A
4

The path to define resources in your app/Resources folder must defined with a trailing: "../"

{% javascripts 
  "../app/Resources/js/qtip.jquery.js"
  "../app/Resources/js/layout.js"
  "@HomeBundle/Resources/js/*"  
%}

Not entirely sure how to help you on your first question, though, but hopefully this can help.

Amoeba answered 4/11, 2011 at 0:41 Comment(0)
I
0

I think you want something along the lines of

{% javascripts '@NameOfYourBundle/path/from/bundle/root/to/jquery-1.6.2.js' %}
Invigilate answered 3/8, 2011 at 13:25 Comment(1)
That works for bundle resources, but not for global resources that reside in /app/Resources directory. Maybe this is by design, just to keep things separated. But you can reference global template app/Resources/view/base.html.twig like this in twig: {% extends '::base.html.twig' %}. So why it should not work for css in {% stylesheets %} ?Entertainment

© 2022 - 2024 — McMap. All rights reserved.