fffunction / twig-static
A filter that takes a static file path and returns a URL versioned with the file hash
Installs: 42
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
pkg:composer/fffunction/twig-static
Requires (Dev)
This package is not auto-updated.
Last update: 2025-10-26 07:49:45 UTC
README
composer require fffunction/twig-static
Usage
Add the filter to Twig:
$twig->addFilter('static', new Twig_Filter_Function( create_static_filter('path/to/assets/', '/url/to/prepend/') ));
Then pass paths to the filter in your templates:
{{ 'js/app.bundle.js' | static }}
{# /url/to/prepend/js/app.bundle.js?v=1a2b3c4 #}
API
create_static_filter(sting $asset_root, string $asset_url): function
$asset_root: a relative path from the app root to the assets root dir$asset_url: a path to prepend to the returned url