PHPackages                             jadu/twig-attribute-parser - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jadu/twig-attribute-parser

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jadu/twig-attribute-parser
==========================

Takes an array of attributes to be converted into HTML formatted attributes ready for use in an HTML element.

1.0.0(2y ago)0262MITPHP

Since Sep 19Pushed 2y ago6 watchersCompare

[ Source](https://github.com/jadu/twig-attribute-parser)[ Packagist](https://packagist.org/packages/jadu/twig-attribute-parser)[ RSS](/packages/jadu-twig-attribute-parser/feed)WikiDiscussions main Synced 1mo ago

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

Twig Attribute Parser
=====================

[](#twig-attribute-parser)

Takes an array of attributes to be converted into HTML formatted attributes ready for use in an HTML element.

The optional `tag` attribute will also generate the required HTML element and is useful for contextually switching elements within Twig views.

Output will always begin with an empty space to avoid unwanted spaces if no attributes are passed to the markup.

Example
-------

[](#example)

```
{%
    set arrayToProcess = ['slim': 'shady', 'marshall': 'mathers', 'eminem': true, 'class': 'wrapper']
%}

{# output:  #}
```

Boolean attributes
------------------

[](#boolean-attributes)

Boolean attribute values will output the key only. The `disabled` boolean attribute behavior is contextual based on the presence and type of an optional `tag` (see below).

```
{%
    set arrayToProcess = ['foo': true]
%}

{# output:  #}
```

Disabled attribute
------------------

[](#disabled-attribute)

The `disabled` attribute is only valid on specific elements, if you attempt to pass a boolean `disabled` attribute without a valid `tag` or to a tag which doesn’t support the disabled attribute, it will output an `is-disabled` class instead which you can style appropriately.

```
{%
    set arrayToProcess = ['disbled': true]
%}

{# output:  #}
```

If a `class` attribute is also present, the class list will be merged appropriately. If the `class` list also contains `is-disabled` it will not be duplicated.

```
{%
    set arrayToProcess = ['class': 'foo', 'disbled': true]
%}

{# output:  #}
```

If `tag` is `button`, `fieldset`, `input`, `option`, `select`, `textarea` or `div`, it will output the disabled attribute.

```
{%
    set arrayToProcess = ['disbled': true]
%}

{# note the absence of the element here, we let the attribute parser output it #}

{# output:  #}
```

If you want the output to be `disabled class="disabled"` you will need to pass both attributes in your array.

If `tag` is `a`, it will add the `aria-disabled` attribute instead as an opinionated accessibility choice.

```
{%
    set arrayToProcess = ['disbled': true]
%}

{# output:  #}
```

HTML entities
-------------

[](#html-entities)

HTML entities will be properly quoted to suit HTML markup, this allows embedded HTML to be passed within attributes for later rendering, for example in tooltops.

```
{%
    set arrayToProcess = ['foo': 'bar baz']
%}

{# output:  #}
```

Empty values
------------

[](#empty-values)

Empty values will be removed, if you want to display only the key, use a boolean instead.

```
{%
    set arrayToProcess = ['foo': '']
%}

{# output:  #}
```

Nested/multidimensional arrays
------------------------------

[](#nestedmultidimensional-arrays)

Not supported.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

971d ago

### Community

Maintainers

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

---

Top Contributors

[![Stanton](https://avatars.githubusercontent.com/u/18653?v=4)](https://github.com/Stanton "Stanton (4 commits)")

### Embed Badge

![Health badge](/badges/jadu-twig-attribute-parser/health.svg)

```
[![Health](https://phpackages.com/badges/jadu-twig-attribute-parser/health.svg)](https://phpackages.com/packages/jadu-twig-attribute-parser)
```

###  Alternatives

[stfalcon/tinymce-bundle

This Bundle integrates TinyMCE WYSIWYG editor into a Symfony2 project.

2692.9M24](/packages/stfalcon-tinymce-bundle)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)

PHPackages © 2026

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