{{#notContains}} helper
The {{#notContains}}
helper is a custom Handlebars helper designed to determine if a given value does not exist within a comma-separated string. This can be particularly useful for rendering parts of your template conditionally based on the absence of specific values.
Syntax:
{{#notContains valueToSearch valueToCheck}}
// Content to render if the valueToCheck does NOT exist inside the
valueToSearch
{{/notContains}}
valueToSearch
: The comma-separated string you want to check against.valueToCheck
: The value you are looking to find the absence of in thevalueToSearch
string.
Examples:
{{#notContains 'abc,def' 'xyz'}}
'abc,def' does not contain 'xyz'
{{/notContains}}
{{#notContains "1,2,3" id}}
// Content to render if the 'id' is NOT found within "1,2,3"
{{/notContains}}
The first example verifies that 'xyz' is not present in 'abc,def'. Since 'xyz' is indeed absent, the content within the
{{#notContains}}
block is rendered, confirming that 'abc,def' does not contain 'xyz'.In the second example, the goal is to check for the absence of a specific
id
within "1,2,3". For clarity and accuracy in our documentation, let's correct the explanation to align with the example provided: Supposeid
has a value that is not listed in "1,2,3". For instance, ifid
is set to '4', then since '4' is not found within "1,2,3", the content within the{{#notContains}}
block will be rendered.
Examples output:
'abc,def' does not contain 'xyz'
Assuming id is '4', the corrected output for the second example should explicitly state that '1,2,3' does not contain '4', aligning with our provided examples:
If id = 4, then the output would be: '1,2,3' does not contain '4'
The {{#notContains}}
helper is versatile and supports checking for the absence of both strings and numbers within a comma-separated string. It provides a straightforward way to conditionally render content based on whether specific values are not present, enhancing the dynamic capabilities of your Handlebars templates.