Hi Community,
We're currently using Handlebars to display a Note in our HTML. Our currently logic to only display the HTML if it contains the word "Sofa" in the name, which worked fine for our previous needs. BUT, if it does contain the word "Sofa" and also contains the word "Cover" in the name, we don't want the HTML to display.
Example of current logic:
{{#each shoppingCartItems}} {{#ifContainsStr name "Sofa"}} {{#assign "hasSofa"}} true {{/assign}} {{/ifContainsStr}} {{/each}}
We've tried the {{#unless}} and also (not) helpers, but the HTML is still being displayed. Would love some insight to how we could modify to our code to get the desired result.
Thanks all.
Hi Chris,
Thanks for reaching out, and I am happy to help provide some handlebar logic that might work with your use case. If you are looking to exclude a field with the string "sofa cover", it is best to use the #ifMatchesRegexStr operator to check and see if your users have this field, if so, we can put custom messaging or leave the area of "Don't render" blank.
We then can check if the user has any other fields with the string "Sofa" to populate the message you'd like:
{{#each shoppingCartItems}}{{#ifMatchesRegexStr name "Sofa .*[Cc]over.*"}}Don't render{{else}}{{#ifContainsStr name "Sofa"}}{{#assign "hasSofa"}} true {{/assign}} I have a sofa field{{/ifContainsStr}}{{/ifMatchesRegexStr}}{{/each}}
I hope this helps!
Best,
Julia
Reply
Create a new Iterable Plaza community account
Already have an account? Login
Login to the Iterable Plaza Community
Not a customer? Create an account
Log in to Iterable (SSO)
Iterable customers and employees login/create an accountEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.