hearsayit / HearsayRequireJSBundle

RequireJS integration for Symfony2.
130 stars 55 forks source link

Adding the option for the require.js path to be in the config #3

Closed bigethan closed 12 years ago

bigethan commented 12 years ago

I'm new to Symfony2, so I may have missed something obvious. And if so, I'd love to be corrected :-)

The only real effect of this code change, other than slightly greater complexity, is that I had to alter the initialization template to print the uri via a

rather than a

as I couldn't find a good way to override the block from a config setting without having to duplicate the code along in the templates.

Why? It feels more natural to me to have the require.js path in the same area as it's namespaces rather than in a template (the initialize template, or the template where they are overriding the block).

Also, I never could figure out how to override that block (see aforementioned newness to S2).

AsaAyers commented 12 years ago

I also like the idea of changing the path in a config better than overriding it with a block.

I usually organize my templates to have each template extend "MyBundle::base.html.twig" and then I have that file extend "::base.html.twig". That gives me a bundle-specific place to override blocks. I could put my requirejs_src block in my bundle's base.html.twig. I haven't tried it with this bundle yet, but I don't have any reason to believe it wouldn't work.

kmontag commented 12 years ago

I've added a config option for the source URL, but I'd still like to keep the overridable src block in initialize.html.twig - I don't want to assume that everyone's accessing RequireJS from a static URL. A simple use case would be serving a local copy of RequireJS via Assetic.

Concretely, the initialize_template config option can be used to specify an alternate template for initialization, which could e.g. extend 'HearsayRequireJS::initialize.html.twig' and then override the src block to output an Assetic URL.

AsaAyers commented 12 years ago

I just tried my previous suggestion and verified that blocks inside the template that calls require_js_initialize() do not affect this bundle. I added hearsay_require_js.initialize_template to my config.yml, and then had a template of mine extend "HearsayRequireJSBundle::initialize.html.twig" and override the "src" block with an assetic URL.