Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to tell what page you are on shopify liquid

// you can use the 'template' object to check which page you are on.
/**
NOTE: I decided to use {% if %} conditional statements exclusively, 
because a few of Shopify theme's seemed to act strangely when trying 
to do the same by using {% else if %} - You are welcome to give it a 
shot if you like. Otherwise, the below should work fine... :)
**/

{% if template == 'index' %}
	// code to execute on index page goes here
{% endif %}
    
{% if template == 'collection' %}
	// code to execute on collection pages goes here
{% endif %}
    
{% if template == 'product' %}
	// code to execute on product pages goes here
{% endif %}
    
{% if template contains 'page' %}
	// code to execute on other "info" page templates goes here
{% endif %}
Comment

PREVIOUS NEXT
Code Example
Javascript :: delete last character from string js 
Javascript :: select selectedindex jquery 
Javascript :: how to get in an object js 
Javascript :: javascript mod 
Javascript :: external script in react 
Javascript :: javascript timing events 
Javascript :: js blur element 
Javascript :: react native navigation shared element 
Javascript :: get current date javascript yyyy-mm-dd 
Javascript :: callback function js 
Javascript :: init select2 jquery 
Javascript :: parse json c# 
Javascript :: reverse keys and values in object javascript 
Javascript :: regular expression in elastic 
Javascript :: javscript match word in string 
Javascript :: You must provide either mongoUrl|clientPromise|client in options 
Javascript :: nmapscript location 
Javascript :: how to access key value pair in javascript 
Javascript :: how to generate a new page component in angular 
Javascript :: wait for promise javascript 
Javascript :: javascript bind this to anonymous function 
Javascript :: console vuex data 
Javascript :: angular implementing Validator 
Javascript :: what is the difference between let and const in javascript 
Javascript :: stop mousemove event javascript 
Javascript :: javascript non-repeating randomize array 
Javascript :: match 
Javascript :: react pass props to children 
Javascript :: convert namednodemap to object 
Javascript :: javascript if statement 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =