How can I do custom code for a specific product template page ?

Solved

How can I do custom code for a specific product template page ?

Aaron33aaron
Tourist
10 0 1

I have a custom product page template on my shopify store that's different than my default product page template and I would like to know where I can put custom code for this page. I can find the .json file for this custom template but not the .liquid file. When I add custom code to the main-product.liquid it adds it to the custom template page so I'm assuming custom templates for product pages still pulls from the main-product.liquid.

 

In this case is there a way to do something like  {% if template.name == 'product.custom-product-page' %} <!-- code to run if the current page is a product page with the custom-product-page template --> {% endif %}  

 

Basically any way to do custom code for a specific template page even if it means going through the main-product.liquid because it seems as if templates pull from this and don't create their own .liquid only a .json

 

If you need more information to answer my question please ask thank you in advanced !

Accepted Solution (1)
AnneLuo
Shopify Partner
922 172 195

This is an accepted solution.

Please use 'template.suffix'

{% if template.suffix == 'custom-neon-quote-product' %}

{% endif %}


Hopefully it will help you. If yes then Please don't forget hit Like and Mark it as solution!

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me   

Buy Me A Coffee

View solution in original post

Replies 7 (7)

PageFly-Richard
Shopify Partner
4584 1051 1711

Hi @Aaron33aaron 

 

This is Richard from PageFly - Shopify Page Builder App

 

You are correct, in this case simply put the condition code in the theme.liquid file, for example:

 

{% if template.name == 'product.custom-product-page' %} 
<style></style>
{%endif%}

So this style only triggers on that product page 

 

Hope this can help you solve the issue 

 

Best regards,

Richard | PageFly 

Please let me know if it works by giving it a Like or marking it as a solution!


➜ Optimize your Shopify store with PageFly Page Builder (Free plan available) 


All features are available from Free plan. Live Chat Support is available 24/7.

Aaron33aaron
Tourist
10 0 1

Hey thanks for the reply,

 

I understand the code but why would I put it in the theme.liquid page if I want it to show up on product.liquid page but only render for specific templates ? Can you clarify this. Also is there a way to get the exact naming covention for a specific product template I created  ?

AnneLuo
Shopify Partner
922 172 195

Yes, your idea is correct. You can use template.name to determine which page you are on.

Can you take a screenshot to describe your requirements? So that I can assist you.

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me   

Buy Me A Coffee

Aaron33aaron
Tourist
10 0 1

Where would I enter template.name code ? I tried entering it into main-product.liquid but doesn't seem to work. Also if my template is named custom-neon-quote-product would i be typing {% if template.name == 'product.custom-neon-quote-product' %}  or {% if template.name == 'custom-neon-quote-product' %} or some other naming convention ?

AnneLuo
Shopify Partner
922 172 195

This is an accepted solution.

Please use 'template.suffix'

{% if template.suffix == 'custom-neon-quote-product' %}

{% endif %}


Hopefully it will help you. If yes then Please don't forget hit Like and Mark it as solution!

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me   

Buy Me A Coffee

Aaron33aaron
Tourist
10 0 1

Thank you so much this worked ! For anyone else wondering I placed it in the main-product.liquid and just referenced the template that I wanted to add code for.

AnneLuo
Shopify Partner
922 172 195

You are welcome. I'm glad to hear that the solution worked well for you.
If you require any more help, please don't hesitate to reach out.

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me   

Buy Me A Coffee