Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/braunstetter/assets-push-bundle

A clean and easy way to extend your assets (css, js) from any point inside of your twig templates.
https://github.com/braunstetter/assets-push-bundle

asset-management assets symfony twig twig-extension twig-templates

Last synced: about 1 month ago
JSON representation

A clean and easy way to extend your assets (css, js) from any point inside of your twig templates.

Awesome Lists containing this project

README

        

# AssetsPushBundle

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/braunstetter/assets-push-bundle/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/braunstetter/assets-push-bundle/?branch=main)
[![Build Status](https://app.travis-ci.com/Braunstetter/assets-push-bundle.svg?branch=main)](https://app.travis-ci.com/Braunstetter/assets-push-bundle)
[![Total Downloads](http://poser.pugx.org/braunstetter/assets-push-bundle/downloads)](https://packagist.org/packages/braunstetter/assets-push-bundle)
[![License](http://poser.pugx.org/braunstetter/assets-push-bundle/license)](https://packagist.org/packages/braunstetter/assets-push-bundle)

Push your assets from everywhere inside your templates into the ``.

## Installation

`composer require braunstetter/assets-push-bundle`

## Usage

After the installation you can use the two tags from each template to register additional resources.

```html
{% 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:

```php
[
'css' => [
'/breadcrumbs.css',
'/custom.css',
'/app.css',
],

'js' => [
'/breadcrumbs.js'
],
]
```

Now you can use this on top of your pages:

```html


{% block title %}Welcome!{% endblock %}

{% block metadata %}{% endblock %}

{% block pushedJs deferred %}
{% for asset in assets()['js'] %}

{% endfor %}
{% endblock %}

{% block pushedCSS deferred %}
{% for asset in assets()['css'] %}

{% endfor %}
{% endblock %}

```