SymfonyTwigExtensions
This is a collection of Twig extensions that I use in symfony., (*1)
Grunt Asset Cache Bust
Extension when using Grunt plugin Cache Bust. See https://github.com/hollandben/grunt-cache-bust, (*2)
How to install
composer require treeleaf/symfony-twig-extensions
How to use in Symfony
In app/config/services.yml:, (*3)
services:
my_app.twig.grunt_cache_bust:
class: Treeleaf\Twig\Extension\GruntAssetCacheBust
public: false
tags:
- { name: twig.extension }
In a twig template:, (*4)
<script src="/{{ gruntCacheBust('grunt-cache-bust.json', 'js/app.js') }}"></script>
Grunt
Example Gruntfile.js:, (*5)
cacheBust: {
options: {
assets: ['css/*', 'js/*']
},
all: {
options: {
expand: true,
queryString: true,
jsonOutput: true
},
src: ['/js/**/*.js', '/css/**/*.css']
}
}
This will by default generate a json artefact grunt-cache-bust.json with a mapping of the source file and the hashed file., (*6)
Example grunt-cache-bust.json:, (*7)
{
"js/vendor.js":"js/vendor.js?82f8fc4bb7e495e6",
"js/app.js":"js/app.js?4df6c65674ecfa3d",
"css/main.css":"css/main.css?362da3994e41aa48"
}