StubbornShowaGuy StubbornShowaGuy - 1 year ago 167
Twig Question

Symfony2/Assetic: Use bundle annotation in asset path for imported HTML files

I am using Symfony 2.8 for my single page web application. I have a file

which is supposed to serve all the required resources. Maybe it's obvious, but I want everything to be reloaded every time in the development environment, but not in the production environment. Said required resources is loaded from another bundle's
located in the

For this reason, I have configured Assetic in
as stated below:

debug: "%kernel.debug%"
enabled: "%kernel.debug%"
enabled: "%kernel.debug%"

(I am assuming that debug is only enabled in the development environment)

I am loading the required CSS/JavaScript like this:

{% stylesheets
'@StubbornShowaBundle/Resources/public/showa.css' %}
<link type="text/css" href="{{ asset_url }}" rel="stylesheet" />
{% endstylesheets %}
{% javascripts
'@StubbornShowaBundle/Resources/public/showa.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

..which seems to be working as intended. However, I also have imported HTML files. Like this one:

<link href="{{ asset('@StubbornShowaBundle/Resources/public/polymer/my-component.html') }}" rel="import"/>

However, the above code does not work. The
annotation seems like it is not usable in the
command. Also, there seems to be no "loop method" (or whatever you want to call that thing for
) for HTML imports. If I link to the file in question directly, aside from stooping to an ugly hack that completely breaks uniformity with the surrounding code, I also break the whole Symfony/Assetic automatically taking care of resource reordering system and debugging becomes a mess. How do I solve this in a way that doesn't force me to re-dump the assets every time I change the code while debugging? (Is it possible to solve in a reasonable way?)

Answer Source

It seems that it is not possible to use HTML imports in Assetic the same way it's used for JavaScript, CSS and images. To quote from the manual:

You can use Assetic to process CSS stylesheets, JavaScript files and images.

What should be done instead depends very much on the case(the requirements) as far as I can see. Perhaps making everything into templates is also a possibility, but in my particular case I had to import Polymer components so making those HTML files into templates would have been a nightmare(because of the conflicting syntax, and whatnot). So I got the path using url, and used the method described in this answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download