In Shopify theme for Product details page we have something like
{{ product.description }}
to show product description, now I want to check for a specific text within the description and based on that do something, for example, something like
if( {{ product.description }} hastext "On Sale"){
// do something
}
else{
do something
}
I want to know the syntax for above implementation in product-template.liquid Thanks!
You have the contains
operator.
Please refer to the Shopify documentation: https://help.shopify.com/themes/liquid/basics/operators
In code:
{%- if product.description contains "On Sale" -%}
// do something
{%- else -%}
// do something
{%- endif -%}