I have following code:

{% set some_base_class = some_base_class|default('is-default') %}
<sometag {{ bem(some_base_class, some_modifiers, some_blockname) }}>somestuff</sometag>

. I embed this code in another component like {% embed "@atoms/somethings/something.twig" with { some_base_class: 'is-not-default' } %}.

What I expect:
<sometag class="is-not-default">somestuff</sometag>

What I get:
<sometag class="is-not-default is-not-default--">somestuff</sometag>

This is, I guess, due bem() accepting only arrays as arguments for modifiers and extra classes, but in twig, undefined variables are empty strings or null or I don't know what, but not empty arrays. I could of course write many lines of twig code like {% set some_modifiers = some_modifiers|default([]) %}, but it would be better if bem() function would check if passed modifiers and extra classes arguments are defined or not empty string.

CommentFileSizeAuthor
#6 empty-modifiers-3157198-6.patch663 byteshenrijs.seso
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 3157198-7 Comparecompare
  • 2.x Comparecompare

Comments

mansspams created an issue. See original summary.

marcel66 made their first commit to this issue’s fork.

marcel66’s picture

Hello,

I confirm this issue on my machine. (Ubuntu, Drupal8). Bem function receive $modifiers variable as null, even defaults to array().

I have made an issue fork to solve the problem. I have only added a new condition to verify if $modifiers are null.

marcel66’s picture

Category: Feature request » Bug report
Status: Active » Needs review
henrijs.seso’s picture

Status: Needs review » Active

Hello :)

There is currently nothing to review. Your branch is same as original. Did you push anything? How about a patch here?

henrijs.seso’s picture

Status: Active » Needs review
StatusFileSize
new663 bytes

OK, let's see if this change in .patch format works...

henrijs.seso’s picture

Title: Empty modifiers added if modifiers not empty array » Empty modifiers added if modifiers are NULL
henrijs.seso’s picture

Why u no run test, bot?

psebborn’s picture

Status: Needs review » Reviewed & tested by the community

Tested on this on a project I'm working and it's working great for me, thanks for the patch!

codechefmarc’s picture

Status: Reviewed & tested by the community » Fixed

Cleaning out some older issues here. I believe this was fixed in the 2.0.1 release and is also available in the 4.0.0 (current) release. See here:

https://github.com/emulsify-ds/emulsify_twig/pull/28

If this is still a problem, please open a new issue. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.