3

I'm currently struggling with this requirement: We've got a modular app which where modules can be enabled by the customer on demand. Each module is a bundle. Now we've got some kind of dashboard where I'd like to inject assets (JS/CSS) based on the modules/bundles installed. In addition I'd like to merge those files into a single "dashboard.{js|css}" file so that we don't have 1 request per each bundles js and css file.

For other files we use a combination of Twig's Assetic integration and named assets, but it doesn't seem that the configuration key assetic.assets can be accessed publically in a bundle's extension class... which is a pity as it'd be an awesome easy way for our approach.

I also looked into a custom config/service couple to inject an asset loader into assetics AssetManager service... but this feels like a total overkill and I think that I simply missed something.

Any idea?

Update 1

I'm aiming for the following configuration:

assetic: # Assetic Configuration
    assets:
        dashboard_js: 
            inputs:
                - '@ModuleOneBundle/Resources/public/js/dashboard.js'
                - '@ModuleTwoBundle/Resources/public/js/dashboard_dep.js'
                - '@ModuleTwoBundle/Resources/public/js/dashboard.js'
                - '@ModuleThreeBundle/Resources/public/js/dashboard.js'

Our customers can decide which modules they use and therefore I cannot hardcode them. So I was trying to use the Configuration classes, but they don't have access to what I need. I'd like to prevent to run custom build scripts to create config.yml files.

althaus
  • 2,009
  • 2
  • 25
  • 33

1 Answers1

0

you can use the the assetic config for this to compile one file with all your needes for each bundle. Maybe you can have a bunch of these entries in your config, all customized, then only call the one file that has your combination yuou need. e.g.

assetic: # Assetic Configuration
    assets:
        js1combo: 
            inputs:
                - '@AppBundle/Resources/public/js/js1.js'
                - '@AppBundle/Resources/public/js/js2.js'
        js2combo: 
            inputs:
                - '@AppBundle/Resources/public/js/js2.js'
                - '@AppBundle/Resources/public/js/js3.js'
        js3combo: 
            inputs:
                - '@AppBundle/Resources/public/js/js1.js'
                - '@AppBundle/Resources/public/js/js2.js'

in your files, only one js file needed

{% javascripts
    'js/js2combo.js'
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

if it helps, i have a tool that can make your compiling tasks alot easier, you can run it once a day.. im trying to get the work out if anybody can help. this has made my assetic life easier. :-)

https://github.com/wolfdogg/symphAstman

Im not understanding your 2nd problem completely, but it sounds like you might want to make a service for that if its too involved the way your having to do it.

blamb
  • 4,220
  • 4
  • 32
  • 50
  • My problem is that I cannot hardcode the input files in `config.yml`. I'll update my question to show my target configuration I'm aiming for. – althaus Feb 26 '15 at 08:27