braunstetter / assets-push-bundle
A clean and easy way to extend your assets (css, js) from any point inside of your twig templates.
Installs: 48
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8
- rybakit/twig-deferred-extension: ^3.0
- twig/twig: ^3.3
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: ^4.2
- nyholm/symfony-bundle-test: ^1.8
- symfony/framework-bundle: ^4.4|^5.0
- symfony/test-pack: ^1.0
- symfony/twig-bundle: ^5.3
- symfony/yaml: ^5.3
README
Push your assets from everywhere inside your templates into the <head>
.
Installation
composer require braunstetter/assets-push-bundle
Usage
After the installation you can use the two tags from each template to register additional resources.
{% css '/breadcrumbs.css' %} {% js '/breadcrumbs.js' %}
After that you are able to query the assets with the assets()
function.
It will give you an array of assets like that:
[ 'css' => [ '/breadcrumbs.css', '/custom.css', '/app.css', ], 'js' => [ '/breadcrumbs.js' ], ]
Now you can use this on top of your pages:
<head> <meta charset="UTF-8"> <title>{% block title %}Welcome!{% endblock %}</title> {% block metadata %}{% endblock %} {% block pushedJs deferred %} {% for asset in assets()['js'] %} <script src="{{ asset(asset) }}" defer></script> {% endfor %} {% endblock %} {% block pushedCSS deferred %} {% for asset in assets()['css'] %} <link rel="stylesheet" href="{{ asset(asset) }}"> {% endfor %} {% endblock %} </head>