Naveed Mazhar
Naveed Mazhar

Reputation: 23

More than one conditions in {{#if}} statement in bigcommerce stencil

I want to use 2 conditions in stencil theme (bigcommerce). How can I do so?

{{#if schema && product.brand.name '!=' ''}}

I have also used

{{#all schema product.brand.name '!=' ''}}

but did not get the desired result.

Also how can we check whether some variable or property is empty or not because following statement did not work for me:

{{#if product.brand.name '==' ''}}

Regards,

Upvotes: 2

Views: 3190

Answers (1)

Nathan Booker
Nathan Booker

Reputation: 684

You should be able to use the {{#and}} helper to compare exactly two conditions.

{{#and schema product.brand.name}} There's both a schema and brand name! {{/and}}

This will check that both "schema" and "product.brand.name" evaluate to something truthy (meaning they're defined and they're not explicitly False or 0, etc)

Checking if a variable is empty is similarly just an if statement checking for it being defined:

{{#if customer}} There's a customer! {{/if}}

There's lots of good examples of these helpers being used in the Cornerstone repo, it might be helpful to search that repo for a few examples to get a feel for things.

Here's an example of the "and" helper: https://github.com/bigcommerce/cornerstone/blob/3350ea5c2a8cbb53819145bdcdda41dc6fef4f0c/templates/components/products/price-range.html#L1

Hope this helps!

Upvotes: 2

Related Questions