0

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?

Alyss
  • 1,866
  • 1
  • 13
  • 27
PGrapes
  • 15
  • 5
  • Can you explain what you are trying to do that requires a "chain" as opposed to nested? – Alyss Feb 13 '16 at 00:44

2 Answers2

1

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..

Community
  • 1
  • 1
0

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}}
Sylvester Kruin
  • 3,294
  • 5
  • 16
  • 39