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

feature request: optional attribute array values #1

Open
rafaucau opened this issue Dec 16, 2023 · 2 comments
Open

feature request: optional attribute array values #1

rafaucau opened this issue Dec 16, 2023 · 2 comments

Comments

@rafaucau
Copy link

rafaucau commented Dec 16, 2023

It would be nice if something like this could be possible:

html_build_attributes(
  [
    'id' => 'post'
    'class' => [
      'post',
      'post--no-sidebar' => ! $has_sidebar,
      'post--no-thumb'   => ! $has_thumb,
    ],
  ] 
);

I mean, that it would be possible to set as an attribute value an associative array, where elements that are false, null, etc. are excluded.

@rafaucau
Copy link
Author

Something like that works, but it's less elegant:

html_build_attributes(
  [
    'id' => 'post'
    'class' => [
      'post',
      ! $has_sidebar ? 'post--no-sidebar' : null,
      ! $has_thumb ? 'post--no-thumb' : null
    ],
  ] 
);

@mcaskill
Copy link
Owner

I have been planning a rewrite of the PHP library based on the JS package I recently drafted: mcaskill/js-html-build-attributes. Hopefully I'll get it implemented soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants