Re: I have created a button snippet and want to integrate to custom liquid block in product page!

I have created a button snippet and want to integrate to custom liquid block in product page!

MattLo
Excursionist
22 0 3

I have created a new button snippet called "personalize-button.liquid". Inside the liquid, below code is inserted:

 

<button class="personalize-button button--primary" style="width: 100%">Personalized</a>

 

However, I would like the 'personalize button' to be shown conditionally on the product page: only when the product's metafield called "personalize' is filled. So, I created the custom liquid block in product page , with below code entered:

 

{% if product.custom.personalize_url != "blank" %} {% include 'personalize-button' with button_text: 'Personalize'%}{% endif %}

 

but there are error msg pop up.

 

I hope someone can help and instruct me where is the problem. 

Replies 7 (7)

Jasoliya
Shopify Partner
4823 625 1225

Hi @MattLo 

You can add code condition like this

{% if product.metafields.personalize.value != blank %}
  {% include 'personalize-button' with button_text: 'Personalize'%}
{% endif %}

 

Note: must check you have metafield with this name "personalize"

Want custom changes? hire me.
3 months of Shopify for $1/month. Look here.
Email us Or WhatsApp, Try our Free app for product bundles and Codify Order Cancel or Order edit
Want to get Free review and advice for sale on store ?? just text me here
MattLo
Excursionist
22 0 3

not working

MattLo
Excursionist
22 0 3

u mean the above code add to custom liquid block in product page?

NomtechSolution
Astronaut
1245 113 154

 

The error you encountered is likely due to the incorrect usage of the include statement. The correct syntax for passing variables to an included snippet is slightly different. Here's the corrected code for your product page:

{% if product.metafields.custom.personalize != blank %}
  {% include 'personalize-button' with button_text: 'Personalize' %}
{% endif %}

Make sure to replace custom with the appropriate namespace for your metafields.

In your "personalize-button.liquid" snippet, you can access the button_text variable using the include object. Here's an updated version of the snippet:

<button class="personalize-button button--primary" style="width: 100%">{{ include.button_text }}</button>
MattLo
Excursionist
22 0 3

not working too

 

gr_trading
Shopify Partner
1944 145 203

@MattLo 

Can you share the screenshot of error.

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
MattLo
Excursionist
22 0 3

Screen Shot 1.png

 

please guide to create a new functional button block, thx