Search code examples
symfonytwigassetic

How to make Assetic scan Twig templates outside bundle


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?


Solution

  • 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.