How do I display different content in a section based on the product tag?

Solved

How do I display different content in a section based on the product tag?

joevince2
Visitor
2 0 1

I'm trying to customize one of my sections (either a custom Liquid section or a product template section) so that it displays different content based on the product tag (Checkout). For example, if a product has the tag premium, I want to show a special message or block of HTML, but if it doesn't, it should show the default content.

I'm comfortable editing Liquid and JSON templates, but I'm not sure what the best approach is to conditionally display content based on tags within a section.

Has anyone implemented something similar? Is there a reliable way to check for a specific tag inside a section file or a block?

Accepted Solution (1)

Mustafa_Ali
Explorer
430 42 78

This is an accepted solution.

You can do this directly in your section or template file like this:

{% if product.tags contains 'premium' %}
  <!-- Custom content for premium products -->
  <div class="premium-message">
    <p>This is a premium product!</p>
  </div>
{% else %}
  <!-- Default content -->
  <div class="default-message">
    <p>Standard product description goes here.</p>
  </div>
{% endif %}

Where to put this:

  • If you're using product.liquid, put it in the appropriate area where content should change.

  • If you're using a custom section, you can wrap the whole block or a part of it in the {% if %} statement.

View solution in original post

Replies 3 (3)

Mustafa_Ali
Explorer
430 42 78

This is an accepted solution.

You can do this directly in your section or template file like this:

{% if product.tags contains 'premium' %}
  <!-- Custom content for premium products -->
  <div class="premium-message">
    <p>This is a premium product!</p>
  </div>
{% else %}
  <!-- Default content -->
  <div class="default-message">
    <p>Standard product description goes here.</p>
  </div>
{% endif %}

Where to put this:

  • If you're using product.liquid, put it in the appropriate area where content should change.

  • If you're using a custom section, you can wrap the whole block or a part of it in the {% if %} statement.

joevince2
Visitor
2 0 1

Thanks Mate.

Mustafa_Ali
Explorer
430 42 78

hey thank you for your response if you need more help feel free to share it  do not forget to like