Skip to content

Instantly share code, notes, and snippets.

@IvanAdmaers
Created August 27, 2022 00:59
Show Gist options
  • Save IvanAdmaers/20171755f1640a6e0e2eb327fbe66869 to your computer and use it in GitHub Desktop.
Save IvanAdmaers/20171755f1640a6e0e2eb327fbe66869 to your computer and use it in GitHub Desktop.
Includes to Handlebars | Array method
{
includes: function (array, ...args) {
const argumentsLength = args.length - 1;
const options = args[argumentsLength];
for (let i = 0; i < argumentsLength; i += 1) {
const item = args[i];
if (array.includes(item) === false) {
return options.inverse(this);
}
}
return options.fn(this);
},
}

Includes

{{#includes myArray 'apple'}}
  There is an apple!
{{/includes}}

Several includes

{{#includes myArray 'apple' 'orange'}}
  There is an apple and an orange!
{{/includes}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment