Skip to content

Commit

Permalink
feat: wp-280 add "ifno" helper for default values (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Apr 16, 2024
1 parent f75e622 commit fb3167a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions fractal.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ engine.handlebars.registerHelper('eq', function(a, b) {
engine.handlebars.registerHelper('has', function(array, item) {
return array.includes(item);
});
engine.handlebars.registerHelper('ifno', function(value, fallback) {
const output = value || fallback;
return new engine.handlebars.SafeString(output);
});

// Export
module.exports = fractal;
8 changes: 4 additions & 4 deletions src/lib/_imports/_partials/message.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<{{#if tag}}{{ tag }}{{else}}div{{/if}}
class="
c-message
{{#if type}}c-message--type-{{ type }}{{/if}}
{{#if scope}}c-message--scope-{{ scope }}{{/if}}
{{#unless scope}}c-message--scope-global{{/unless}}
{{ifno ns 'c-'}}message
{{#if type}}{{ifno ns 'c-'}}message--type-{{ type }}{{/if}}
{{#if scope}}{{ifno ns 'c-'}}message--scope-{{ scope }}{{/if}}
{{#unless scope}}{{ifno ns 'c-'}}message--scope-global{{/unless}}
"
>

Expand Down

0 comments on commit fb3167a

Please sign in to comment.