Your Shopify theme defines your brand. It decides how your customers interact with your store and has limited options for customization.
Unless you choose to go beyond the UI and dig into the code.
Doing so can allow you to change design elements or add functionality that your theme does not include.
By manually editing Shopify’s template code—called Liquid—you can customize your store to your liking. You may start feeling more powerful but know that you’ll also have the power to break your store.
If you are dead set on editing your Shopify store’s Liquid code, you’ll want to know how it works first.
Luckily, you don’t need to be a coder to tinker with your store’s Liquid code.
This Shopify Liquid tutorial is meant for beginners, avoiding technical jargon where possible and including definitions as needed throughout.
So, buckle up. It’s time to learn about Liquid!
#cta-visual-pb#
Shopify Liquid is an open-source template language that serves as the framework for all Shopify themes. In short, it is the language Shopify is written in.
Although Shopify’s themes may look different, they all boil down to this central codebase.
Liquid is purposely more limited than other programming languages, acting as a simple bridge between store data and HTML. For this reason, it is also described as a template engine or syntax rather than a full-fledged language. However, it uses if/then statements, logic, and loops like any other coding language.
Originally created by Shopify co-founder and CEO Tobias Lütke and written in Ruby, Liquid is now used by other major platforms such as Salesforce and Zendesk.
When looking at a website, you won’t be able to tell the difference between static and dynamic content.
Simply, static content is hard-coded into the page, whereas dynamic content is pulled into a page from a database.
Web developers use template languages to seamlessly combine static content with dynamic content on a page, so you can’t tell the difference.
Static content stays the same from page to page but dynamic content changes. In your Shopify store, static elements are written in HTML, and dynamic elements are written in Liquid.
The Liquid code is essentially a placeholder.
It’s used to retrieve specific referenced data from your Shopify store—like your store name, product details, images, etc.—when the code is compiled and sent to the browser. Then, the browser grabs assets like your Javascript and CSS files to display your customized theme.
This allows Shopify themes to be agnostic, meaning the same code can work for many stores without adjustments.
This makes changing your Shopify theme a rather painless process.
Liquid is an easy language to recognize.
Beyond its very identifiable .liquid file extension, Liquid also uses two unique delimiters—characters used to separate independent parts in a piece of code—to define objects and tags within template files.
Filters can be used within the double curly braces to alter the output of an object.
Liquid is characterized by three key parts: objects, tags, and filters.
Objects (also known as variables) represent one or more values. They can stand in for anything from titles to numbers to calculation results to database query results.
In Liquid, objects (wrapped in double curly braces) output pieces of data onto the page.
A single object can support many different properties, and a dot syntax system separates the object from its property.
For example, in the object {{ page.title }}, the term before the dot is the object, and the term after the dot is the property. So, this would output the title property of the page object.
This simple Liquid syntax makes using it super user-friendly.
Tags (wrapped in curly braces and percentage signs) are used to create logic for templates.
While tags are themselves not rendered on the page, they determine how objects are displayed on the page or whether they are displayed at all.
For example, a tag could instruct your store page to show the price of an item if it’s available and if it isn’t available, to display a “sorry, this item is currently sold out” message.
Filters are used to modify outputs. Indicated by the pipe character, filters can do many things to change how an object is displayed on the page.
For example, to maintain sentence case for certain objects, you could use the capitalize filter like so: {{ “a badly CAPITALIZED Title” | capitalize }} outputs A badly capitalized title.
To bring all these concepts together, let’s look at the Liquid code for the pre-formatted contact page of Shopify’s Debut theme.
Objects and tags are bolded to show the Liquid code more clearly.
———————————————
{{ page.title }}
{% if page.content.size > 0 %}
{{ page.content }}
{% endif %}
{%- assign formId = ‘ContactForm’ -%}
{% form ‘contact’, id: formId %}
{% include ‘form-status’, form_id: formId %}
type=”email”
id=”{{ formId }}-email”
name=”contact[email]”
autocorrect=”off”
autocapitalize=”off”
value=”{% if form.email %}{{ form.email }}{% elsif customer %}{{ customer.email }}{% endif %}”
aria-required=”true”
{%- if form.errors contains ’email’ -%}
class=”input–error”
aria-invalid=”true”
aria-describedby=”{{ formId }}-email-error”
{%- endif -%}
>
{%- if form.errors contains ’email’ -%}
{%- endif -%}
{% endform %}
—————————————
We can see examples of the three Liquid features throughout this piece of code:
This is what the code translates to on the front end:
To show how your store’s front end is affected by your theme’s Liquid code, let’s replace the form on this contact page with some text.
Before you edit your theme code, duplicate your theme and make your changes in the duplicate version.
That way, any mistakes you make can be easily reversed.
Just click “Actions” on the theme and choose “Duplicate” from the dropdown menu.
Open the “Actions” menu on your duplicate theme and select “Edit Code” to open the Shopify code editor.
In the code editor, open the page.contact.liquid file.
Highlight the portion of the code that creates the form. It begins with a div and ends with an endform tag.
Ensure you’ve highlighted the correct code and delete it. Save your changes.
Back in your dashboard, navigate to your Contact page.
In the body section of your Contact page, add in the details that will replace the form.
The page.contact.liquid file will pull this info with the {{ page.content }} object.
Click “Save.”
When you preview the page, you’ll see that the form is gone and your new information has been added in its place.
#cta-visual-pb#
Objects are the foundation of Liquid.
After all, they are the feature that determines what visitors to your store can actually see.
Content objects output template and section file content for your Shopify store, plus any stylesheets or scripts created by Shopify or apps.
Global objects (AKA global variables) are accessible from any Liquid file in your theme.
They are used to pull the following pieces of data from your store:
Remember that all of these objects have up to dozens of properties, which each have a function of their own.
Also, many objects aren’t considered content objects or global objects.
Tags are a little more active than objects. They can create loops, run conditional if/then statements, and change how objects are displayed.
There are four types of tags:
Filters live within an object’s curly braces, augmenting its output based on many different actions.
The different types of filters include:
By now, you have learned a lot about what Liquid is and how it works from this lovely Shopify Liquid tutorial.
If you would like to learn more about this subject, we recommend the following resources:
By understanding the code behind your Shopify theme, you’ll be able to turn your ideas for pages into a reality.
If you’d rather skip the code, you can always start customizing your Shopify store with Shogun Page Builder. Drag and drop page elements together—customize each one to your brand specifications—to elevate your current theme’s functionality.
You can even create custom code blocks to use across your Shopify store.
#cta-visual-pb#