PHPackages                             rahid/macros-assets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. rahid/macros-assets

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

rahid/macros-assets
===================

Un bundle Symfony pour gérer les macros Twig liées aux assets.

1.0.0(8mo ago)00MITPHPPHP &gt;=8.1

Since Oct 8Pushed 4mo agoCompare

[ Source](https://github.com/rhidja/macros-assets)[ Packagist](https://packagist.org/packages/rahid/macros-assets)[ RSS](/packages/rahid-macros-assets/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Macros Assets Bundle
====================

[](#macros-assets-bundle)

[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/e125c4cc78f074322c7078f5fc0fbdf75aeb6332d7d17818ea9a97238740d855/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726869646a612f6d6163726f732d6173736574733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/e125c4cc78f074322c7078f5fc0fbdf75aeb6332d7d17818ea9a97238740d855/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726869646a612f6d6163726f732d6173736574733f7374796c653d666c61742d737175617265)[![GitHub issues](https://camo.githubusercontent.com/b9294243f2091331ba3d54061feaec1a69ce42fcb079a5c1590a1d292fdf4a95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f726869646a612f6d6163726f732d6173736574733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/b9294243f2091331ba3d54061feaec1a69ce42fcb079a5c1590a1d292fdf4a95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f726869646a612f6d6163726f732d6173736574733f7374796c653d666c61742d737175617265)[![GitHub license](https://camo.githubusercontent.com/7808d9410906316f60434ed4bf5949f1397d48792c622dcac862c30f5239d472/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726869646a612f6d6163726f732d6173736574733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7808d9410906316f60434ed4bf5949f1397d48792c622dcac862c30f5239d472/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726869646a612f6d6163726f732d6173736574733f7374796c653d666c61742d737175617265)

**A Symfony bundle for registering and rendering Twig macro assets in your templates.**

Table of Contents
-----------------

[](#table-of-contents)

- [Description](#description)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)

Description
-----------

[](#description)

This bundle allows to track Twig macros usage at runtime across your Symfony application, so CSS and JS can be loaded dynamically depending on the macros used in the rendered template.

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- Symfony 6.0 or higher
- PHP 8.1 or higher

### Step 1: Add the project repository

[](#step-1-add-the-project-repository)

In the main `composer.json`, add:

```
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/rhidja/macros-assets.git"
    }
]
```

### Step 2: Install via Composer

[](#step-2-install-via-composer)

```
composer require rhidja/macros-assets
```

### Step 3: Register the bundle

[](#step-3-register-the-bundle)

Add the bundle to your `config/bundles.php` file:

```
return [
    // ...
    Rahid\MacrosAssets\RahidMacrosAssets::class => ['all' => true],
];
```

### Step 4: Configure macros

[](#step-4-configure-macros)

Create `config/packages/macros_assets.yaml`:

```
rahid_macros_assets:
    input:
        css:
            - build/css/style-1.css
            - https://style-2.css
        js:
            - build/js/script-1.js
            - build/js/script-2.js
    textarea:
        css:
            - build/css/style-3.css
            - https://style-4.css
        js:
            - build/js/script-5.js
            - build/js/script-3.js
```

Usage
-----

[](#usage)

### Define your macros with logging

[](#define-your-macros-with-logging)

```
{# templates/macros/form_macros.twig #}

{% macro input(name, value = '', type = 'text') %}
    {{ _log_macro('input') }}

{% endmacro %}

{% macro textarea(name, value = '') %}
    {{ _log_macro('textarea') }}
    {{ value }}
{% endmacro %}
```

### Use macros in your template

[](#use-macros-in-your-template)

```
{% import 'macros/form_macros.twig' as forms %}

    {{ forms.input('username') }}
    {{ forms.textarea('description') }}
    Submit

```

### Render assets after all macros are called

[](#render-assets-after-all-macros-are-called)

Place this at the end of your layout (after all macro calls):

```
{{ _render_assets() }}
```

This will dynamically insert the CSS and JS associated with the macros used in the template.

Contributing
------------

[](#contributing)

Contributions are welcome! To propose improvements or report issues, please open an issue or submit a pull request.

License
-------

[](#license)

This project is licensed under the **MIT License** – see the [LICENSE](LICENSE) file for details.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance68

Regular maintenance activity

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

269d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9186f19f705831664829b891693be781b6da709db3bdce07482c6cdbe35c43f?d=identicon)[ramdu34](/maintainers/ramdu34)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rahid-macros-assets/health.svg)

```
[![Health](https://phpackages.com/badges/rahid-macros-assets/health.svg)](https://phpackages.com/packages/rahid-macros-assets)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
