0
votes

TLDR: How do I make Assetic scan for assets in Twig templates outside bundle?

I've got few registration wizards. Each of these wizards has it's own view directory, the file structure looks like this:

/SiteBundle/Wizard/General/Resources/views
/SiteBundle/Wizard/CountrySpecific/Resources/views
/SiteBundle/Wizard/[...several more...]/Resources/views

In config.yml I defined these paths for twig so I can use @general_wizard/template.html.twig paths:

twig:
    paths:
        "%kernel.root_dir%/../src/MyWeb/SiteBundle/Wizard/General/Resources/views": general_wizard
        "%kernel.root_dir%/../src/MyWeb/SiteBundle/Wizard/CountrySpecific/Resources/views": country_specific_wizard

The problem is that assets used in these templates (inside the Wizard directories) are not dumped using assetic:dump. When I move the view sources to regular SiteBundle/Resources/views, then all the assets are correctly dumped.

Is there a way to make Assetic check the external templates too?

2

2 Answers

0
votes

It is not possible with the stock assetic:dump (SF 2.3), as the /Resources/views/ path is hardcoded in the GeneratorBundle, which again provides the list of files to process to assetic. Of course, you could write your own command, but you would basically reinvent the wheel.

I would recommend to keep with the Resources/views convention, and create the subcategories below that:

/SiteBundle/Resources/views/General
/SiteBundle/Resources/views/CountrySpecific

That would have the same effect, and would not require you to write your own commands and mess around with SF2 internals.

0
votes

I encountered the same problem after moving all templates to templates in the project root, as it will probably come to be in future versions of Symfony.

The simplest solution is to configure all assets in the configuration file and to locate the output files in the web directory, e.g., all bootstrap CSS files into web/css/bootstrap.css. A remaining difficulty is that referencing the assets with the javascripts tag doesn't work anymore because those tags have to be scanned by the Assetic Bundle to work. You have to do this the old-fashioned way, e.g., via {{ asset('css/bootstrap.js') }}.

With Bootstrap I encountered difficulties to make Glyphicons work, since the cssrewrite filter doesn't work as before. I went for Fontawesome at that point, but including your own copy of Glyphicons could also work.