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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | empty-modifiers-3157198-6.patch | 663 bytes | henrijs.seso |
Issue fork emulsify_twig-3157198
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:
Comments
Comment #3
marcel66 commentedHello,
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.
Comment #4
marcel66 commentedComment #5
henrijs.seso commentedHello :)
There is currently nothing to review. Your branch is same as original. Did you push anything? How about a patch here?
Comment #6
henrijs.seso commentedOK, let's see if this change in .patch format works...
Comment #7
henrijs.seso commentedComment #8
henrijs.seso commentedWhy u no run test, bot?
Comment #9
psebborn commentedTested on this on a project I'm working and it's working great for me, thanks for the patch!
Comment #10
codechefmarcCleaning 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!