PGrapes
PGrapes

Reputation: 15

BigCommerce Stencil & Handlebars

Is there a custom helper available in Stencil to chain multiple conditions rather than nest them?

{{#if template_file '!==' 'pages/home'}}
{{#if template_file '!==' 'pages/product'}}
{{#if template_file '!==' 'pages/category'}}
...

{{/if}}
{{/if}}
{{/if}}

Can the 'any' helper be used in this instance?

Upvotes: 0

Views: 1321

Answers (2)

Natalie Reynolds
Natalie Reynolds

Reputation: 1

You can use an or statement. For example:

{{#or (if template_file '===' 'path/to/file') (if template_file '===' 'path/to/file')}} 
    <html>/{{component(s) to render}}
    {{else}}
        {{#or (if template_file '===' 'path/to/file') (if page.title '===' 'Page Title')}}
    <html>/{{component(s) to render}}
        {{else}}
    <html>/{{component(s) to render}}
    {{/or}}{{/or}}

Upvotes: 0

user1893702
user1893702

Reputation:

See: Logical operator in a handlebars.js {{#if}} conditional

In short, no. You are better off writing your own helper if you plan on using this condition more than once. But then again, maybe it would be better to just declare a global variable on the current page, and then on your 'dynamic' template file, you can have a single conditional statement that compares that single variable?

Does that make sense? Hope this helps..

Upvotes: 1

Related Questions