Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add htmlTagAttributes filter to Twig #4237

Merged
merged 2 commits into from May 10, 2019

Conversation

@timkelty
Copy link
Contributor

commented May 9, 2019

…because yii\helpers\BaseHtml::renderTagAttributes is awesome!

Back in the day I wrote a Craft 2 plugin for this: https://github.com/timkelty/htmlattributes-craft

Now that it can be added to Craft with a couple lines of code, seems like a big win.

Example usage:

{% set attributes = {
      class: ['one', 'two'],
      disabled: true,
      readonly: false,
      data: {
        baz: 'Escape this "',
        qux: {
          some: ['data', '"quoted"']
        }
      },
      style: {
        'background-color': 'red',
        'font-size': '20px'
      },
} %}

<div {{ attributes|htmlTagAttributes }}></div>

@timkelty timkelty force-pushed the timkelty:html-tag-attributes-twig-filter branch from a72e9f3 to fba3d70 May 9, 2019

@brandonkelly

This comment has been minimized.

Copy link
Member

commented May 9, 2019

Couple things:

  • The PR should target the 3.2 branch instead of develop.
  • It should probably be a Twig function rather than filter, since it’s not really modifying the array, as much as generating something completely new using the array for configuration.
  • It should probably just be called attr().

@timkelty timkelty force-pushed the timkelty:html-tag-attributes-twig-filter branch from fba3d70 to ce59516 May 10, 2019

@timkelty timkelty changed the base branch from develop to 3.2 May 10, 2019

@timkelty

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2019

All set, @brandonkelly!

  • The PR should target the 3.2 branch instead of develop.
  • It should probably be a Twig function rather than filter, since it’s not really modifying the array, as much as generating something completely new using the array for configuration.
  • It should probably just be called attr().

@brandonkelly brandonkelly merged commit 8f69e68 into craftcms:3.2 May 10, 2019

1 check passed

Scrutinizer Analysis: 1 updated code elements – Tests: passed
Details
@brandonkelly

This comment has been minimized.

Copy link
Member

commented May 10, 2019

Looks great, thanks!

brandonkelly added a commit that referenced this pull request May 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.