Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Add support for drupal attributes in configuration files #28

Open
David-Czinege opened this issue May 13, 2020 · 0 comments
Open

Add support for drupal attributes in configuration files #28

David-Czinege opened this issue May 13, 2020 · 0 comments

Comments

@David-Czinege
Copy link

I think it should be good, if we can add predefined attributes in config files easily, which are accessible in twig templates as Drupal's attributes object.

Drupal's attribute usage in twig:
https://www.drupal.org/docs/8/theming-drupal-8/using-attributes-in-templates

There is a JavaScript port of the Drupal's Attribute object, which can be used:
https://www.npmjs.com/package/drupal-attribute

It will be good, if all the context values, where the key start with '_' character and ends with '_attributes' are converted into drupal attribute.

So I would like something like this:

With this config.yml:

title: Checkbox
label: Checkbox
status: ready
notes: 'Custom checkbox'
tags: ['checkbox', 'form']
context:
  _wrapper_attributes: {}
  _attributes:
    class:
      - custom-checkbox
      - another-class
    name: checkbox
    id: checkbox
    type: checkbox
  id: checkbox
  label: Regular Option

And with this twig template:

<div{{ wrapper_attributes.addClass('c-checkbox') }}>
  <input{{ attributes.addClass('c-check') }}>
  <label for="{{ id }}">{{ label }}</label>
</div>

I get this HTML output:

<div class="c-checkbox">
    <input class="custom-checkbox another-class c-check" name="checkbox" id="checkbox" type="checkbox">
    <label for="checkbox">Regular Option</label>
</div>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant