https://github.com/fffunction/twig-static
A filter that takes a static file path and returns a URL versioned with the file hash
https://github.com/fffunction/twig-static
Last synced: 8 months ago
JSON representation
A filter that takes a static file path and returns a URL versioned with the file hash
- Host: GitHub
- URL: https://github.com/fffunction/twig-static
- Owner: fffunction
- Created: 2017-07-07T14:03:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-10T09:55:23.000Z (almost 9 years ago)
- Last Synced: 2025-01-12T13:29:04.133Z (over 1 year ago)
- Language: PHP
- Homepage: https://packagist.org/packages/fffunction/twig-static
- Size: 6.84 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# twig-static
[](https://travis-ci.org/fffunction/twig-static)
```
composer require fffunction/twig-static
```
## Usage
Add the filter to Twig:
```php
$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:
```twig
{{ '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