Horizon theme: Custom liquid block not showing

Hi, newbie using Horizon theme and on the Home page the custom liquid block is not showing in the product card, AI checked code many times and all should be working. Here is the code if it helps.

{% if card_product.metafields.custom.from_germany == true %}
From Germany
{% endif %}

Any help greatly appreciated.

1 Like

Hi @Bolzenanker

Welcome to the community.

For your code, where did you copy that? In what file?

Hey @Bolzenanker,

I think a card_product variable should usually be passed into a product-card.liquid snippet or similar when iterating through products (e.g., in a collection grid or featured products section). If you’ve added the custom liquid block via the theme editor, make sure you’ve placed it within a section that actually renders product cards, inside the loop or snippet where card_product is defined.

More often than not, for something like this, you’ll need to edit the product-card.liquid snippet directly (or whatever snippet your theme uses to render individual product cards) to inject the liquid there.

Also, double-check that the metafield custom.from_germany is actually set to true for the products you’re testing with, and that it’s defined as a boolean metafield type. If it’s a text metafield storing “true” or “false” as strings, your condition would need to be {% if card_product.metafields.custom.from_germany == 'true' %}.

Hope that helps!

Thanks you, if i copy here the product-card.liquid code, would you be able to insert it in the right place for me?

Here is the code, can you do me a massive favour and insert it in the correct position?

{% liquid

assign product = block.settings.product

-%}

{% capture children %}

{% content_for ‘blocks’, closest.product: product %}

{% endcapture %}

{% render ‘product-card’, children: children, product: product %}

{% schema %}

{

“name”: “t:names.product_card”,

“blocks”: [

{

  "type": "\_product-card-group"

},

{

  "type": "text"

},

{

  "type": "image"

},

{

  "type": "price"

},

{

  "type": "review"

},

{

  "type": "sku"

},

{

  "type": "swatches"

},

{

  "type": "\_product-card-gallery"

},

{

  "type": "product-title"

},

{

  "type": "custom-liquid"

},

{

  "type": "@app"

}

],

“tag”: null,

“settings”: [

{

  "type": "product",

  "id": "product",

  "label": "t:settings.product"

},

{

  "type": "range",

  "id": "product_card_gap",

  "label": "t:settings.vertical_gap",

  "min": 0,

  "max": 50,

  "step": 1,

  "unit": "px",

  "default": 16

},

{

  "type": "checkbox",

  "id": "inherit_color_scheme",

  "label": "t:settings.inherit_color_scheme",

  "default": true

},

{

  "type": "color_scheme",

  "id": "color_scheme",

  "label": "t:settings.color_scheme",

  "default": "scheme-1",

  "visible_if": "{{ block.settings.inherit_color_scheme == false }}"

},

{

  "type": "header",

  "content": "t:content.borders"

},

{

  "type": "select",

  "id": "border",

  "label": "t:settings.style",

  "options": \[

    {

      "value": "none",

      "label": "t:options.none"

    },

    {

      "value": "solid",

      "label": "t:options.solid"

    }

  \],

  "default": "none"

},

{

  "type": "range",

  "id": "border_width",

  "min": 0,

  "max": 100,

  "step": 1,

  "unit": "px",

  "label": "t:settings.thickness",

  "default": 1,

  "visible_if": "{{ block.settings.border != 'none' }}"

},

{

  "type": "range",

  "id": "border_opacity",

  "min": 0,

  "max": 100,

  "step": 1,

  "unit": "%",

  "label": "t:settings.opacity",

  "default": 100,

  "visible_if": "{{ block.settings.border != 'none' }}"

},

{

  "type": "range",

  "id": "border_radius",

  "label": "t:settings.border_radius",

  "min": 0,

  "max": 32,

  "step": 1,

  "default": 0

},

{

  "type": "header",

  "content": "t:content.padding"

},

{

  "type": "range",

  "id": "padding-block-start",

  "label": "t:settings.top",

  "min": 0,

  "max": 50,

  "step": 1,

  "unit": "px",

  "default": 0

},

{

  "type": "range",

  "id": "padding-block-end",

  "label": "t:settings.bottom",

  "min": 0,

  "max": 50,

  "step": 1,

  "unit": "px",

  "default": 0

},

{

  "type": "range",

  "id": "padding-inline-start",

  "label": "t:settings.left",

  "min": 0,

  "max": 50,

  "step": 1,

  "unit": "px",

  "default": 0

},

{

  "type": "range",

  "id": "padding-inline-end",

  "label": "t:settings.right",

  "min": 0,

  "max": 50,

  "step": 1,

  "unit": "px",

  "default": 0

}

],

“presets”: [

{

  "name": "t:names.product_card",

  "category": "t:categories.product",

  "settings": {

    "product_card_gap": 4

  },

  "blocks": {

    "product-card-gallery": {

      "type": "\_product-card-gallery",

      "settings": {

        "image_ratio": "adapt",

        "border": "none",

        "border_width": 1,

        "border_opacity": 100,

        "border_radius": 0,

        "padding-block-start": 0,

        "padding-block-end": 0,

        "padding-inline-start": 0,

        "padding-inline-end": 0

      }

    },

    "product_title": {

      "type": "product-title",

      "name": "t:names.product_title",

      "settings": {

        "width": "fit-content",

        "max_width": "normal",

        "alignment": "left",

        "type_preset": "rte",

        "font": "var(--font-body--family)",

        "font_size": "1rem",

        "line_height": "normal",

        "letter_spacing": "normal",

        "case": "none",

        "wrap": "pretty",

        "color": "var(--color-foreground)",

        "background": false,

        "background_color": "#00000026",

        "corner_radius": 0,

        "padding-block-start": 4,

        "padding-block-end": 0,

        "padding-inline-start": 0,

        "padding-inline-end": 0

      }

    },

    "price": {

      "type": "price",

      "name": "t:names.product_price",

      "settings": {

        "show_sale_price_first": true,

        "show_installments": false,

        "show_tax_info": false,

        "type_preset": "h6",

        "width": "100%",

        "alignment": "left",

        "font": "var(--font-body--family)",

        "font_size": "1rem",

        "line_height": "normal",

        "letter_spacing": "normal",

        "case": "none",

        "color": "var(--color-foreground)",

        "padding-block-start": 0,

        "padding-block-end": 0,

        "padding-inline-start": 0,

        "padding-inline-end": 0

      }

    }

  },

  "block_order": \["product-card-gallery", "product_title", "price"\]

}

]

}

{% endschema %}

@Bolzenanker

Try this copy

{% if product.metafields.custom.from_germany == true %}
From Germany
{% endif %}

to snippets/product_card.liquid just before

    {{ children }}
  </div>

so it looks like

    {% if product.metafields.custom.from_germany == true %}
       From Germany
    {% endif %}
    {{ children }}
  </div>

And make sure you do have that metafield defined and filled for the product you are testing.

Thank you, but doesn’t seem to make a difference.

Well for me it works but I moved it after all content now.

So snippets/product-card.liquid

Code should be

    {{ children }}

    {% if product.metafields.custom.from_germany == true %}
      <div class="germany_text">From Germany</div>
    {% endif %}
  </div>
</product-card>

Again make sure your metafield is defined with name from_gemany and type True/false and you have set true for product in question.

Superstar, thank you so much.

1 Like

You could definitely use “Custom Liquid” block to avoid theme code edits.

Proper way is to use the Liquid objects: closest like this:

    {% if closest.product.metafields.custom.from_germany == true %}
      <div class="germany_text">From Germany</div>
    {% endif %}

Also, in your theme code you some hints:

{% content_for ‘blocks’, closest.product: product %}
  . . .
{% render ‘product-card’, children: children, product: product %}

Which means that in context of product-card snippet there is an object product defined;
and in context of children theme blocks there is a closest.product (which refers to the same object).

1 Like

Thank you @tim_1

I tried just the product with Custom Liquid, and saw that closest later and tried directly in code, but did not think to try to use it in a block. This is clean and the only proper way.

@Bolzenanker, you see now who is a real superstar. Tims comments are always on point.

So yeah, remove that code from the file and use the Custom Liquid block, as that is the way it should be used, you can drag and drop, position that text wherever you want.

1 Like

Very grateful to everyone, this issue solved, on to the next no doubt. :grinning_face_with_smiling_eyes:

1 Like