Lets Build a Shopify Theme

Let’s Design a Shopify Theme

Mar 6th in Other by Jesse Storimer

Themeforest recently opened a new section where you can buy or sell themes for Shopify! Shopify is a hosted e-commerce solution that makes it easy to get started with an online business. You can have a shop up and running in minutes.

To kick-start ThemeForest's Shopify catalog, the authors of each accepted template will receive a $100 bonus - until there are ten templates in the category.

PG

Author: Jesse Storimer

I'm Jesse. I live in Ottawa, Canada. I'm currently interested in Rails and all things that make web development easier. I have a blog too.

Shopify is well known for its flexibility of design. See some examples. Shopify created (and later released as open source) the Liquid Templating Engine. Liquid allows complete design freedom for designers.

In this tutorial I will show how to design a Shopify theme using Liquid. Once you have the basics, you can design a theme, and submit it to Themeforest.

Let’s Design a Shopify Theme

What is Liquid?

Liquid is the templating engine developed for and used by Shopify. It processes Liquid template files, which have the “.liquid” extension. Liquid files are simply HTML files with embedded code. Since Liquid allows full customization of your HTML, you can literally design a shop to look like anything.

Liquid was originally developed in Ruby for use with Shopify and was released as an open source project. Since then, it has been used in other Ruby on Rails projects, and has been ported to PHP and javascript.

A Quick Preview of Liquid

Let’s look at what it takes to get started with liquid.

  <ul id="products">      
    {% for product in products %}
      <li>
        <h2>{{ product.title }}</h2>
        Only {{ product.price | money_with_currency }}
      
        <p>{{ product.description | prettyprint | truncate: 200 }}</p>
                    
      </li>      
    {% endfor %}      
  </ul>

As you can see, Liquid is just HTML with some embedded code. This is why Liquid is so powerful, it gives you full power over your code and makes it easy to work with the variables you have available.

What is going on above?

Shopify banner

In Liquid, there are two types of markup: Output and Tags. Liquid Tags are surrounded by curly brackets and percent signs; output is surrounded by two curly brackets.

In the above snippet, the first line of Liquid is: {% for product in products %} .... {% endfor %} This is an example of a Liquid Tag. The for Tag loops over a collection of items and allows you to work with each one. If you have ever used for loops in PHP, Ruby, javascript, or (insert any programming language here), it works the same way in Liquid.

The next line of Liquid in the above snippet is {{ product.title }}. This is an example of a Liquid Output. This will ask for a product’s title and display the result to the screen.

The next line of Liquid introduces something new: {{ product.price | money_with_currency }} Here we have an example of a Liquid Filter. They allow you to process a given string or variable. Filters take the value to the left of themselves and do something with it. This particular Filter is called format_as_money; it takes a number, prepends it with a dollar sign and wraps it with the correct currency symbol.

A simple example:

  {{ product.price | money_with_currency }}
could generate the following HTML
  $45.00 USD

The last line of Liquid above: {{ product.description | prettyprint | truncate: 200 }} shows how you can chain filters together. Filters act on the value that is to the left of them, even if that value happens to be the result of another filter. So the snippet in question will apply the prettyprint filter to product.description, and then will apply the truncate filter to the results of prettyprint. In this way, you can chain together as many Liquid filters as you need!

What Else Does Liquid Offer?

In terms of Liquid Tags, besides the for tag, there are several others. Th most common ones are:

Comment:

    {% comment %} This text will not be rendered {% endcomment %}

If/Else:

    {% if product.description == "" %}
      This product has no description!
    {% else %}
      This product is described!
    {% endif %}
 

Case:

    {% case template %}	
      {% when 'product' %}
        This is a product.liquid
      {% when 'cart' %}
        This is a cart.liquid
    {% endcase %}

Check out the full list of Tags.

Liquid also offers plenty of filters you can use to massage your data. Some common ones are:

Capitalize:

  {{ “monday” | capitalize }} #=> Monday

Join:

  {{ product.tags | join: ’, ’ }} #=> wooden, deep snow, 2009 season

Date:

  Posted on {{ article.created_at | date: “%B %d, ’%y” }} #=> Posted on January 26, ’09

Check out the full list of filters available.

Anatomy of a Shopify Theme

Shopify themes all have a simple directory structure. It consists of an assets, layout, and templates folder. Let’s look at what goes where:

  1. assets folder: In the assets folder you store all of the files that you want to use with your theme. This includes all stylesheets, scripts, images, audio files, etc. that you will be using. In your templates you can access these files with the asset_url Filter.

     
        {{ "logo.gif" | asset_url | img_tag: "Main Logo" }} #=> <img src="/files/shops/random_number/assets/logo.gif" alt="Main Logo" />
    
  2. layout folder: This folder should contain just one file called theme.liquid. The theme.liquid holds the global elements for your Shopify theme. This code will be wrapped around all of the other templates in your shop. Here is an example of a very basic theme.liquid:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
          <title>{{shop.name}}</title>
          {{ 'layout.css' | asset_url | stylesheet_tag }}
    
          {{ content_for_header }}
        </head>
    
        <body>
          <div id="header">
            <h1 id="logo"><a href="/">{{ shop.name }}</a></h1>
          </div>
    
          <div id="content">
            {{ content_for_layout }}
          </div>
    
          <div id="footer">
            All prices are in {{ shop.currency }} |
            Powered by <a href="http://www.shopify.com" title="Shopify, Hosted E-Commerce">Shopify</a>
          </div>
        </body>
      </html>
    

    Required Elements

    There are two VERY important elements that must be present in a theme.liquid file. The first is {{ content_for_header }}. This variable must be placed in the head of your theme.liquid. It allows Shopify to insert any necessary code in the document head, such as a script for statistics tracking. For thsoe familiar with WordPress, this is quite similar to the wp_head() function.

    The other VERY important element is {{ content_for_layout }}. This variable must be placed in the body of your theme.liquid; it's the place where all of your other Liquid templates will be rendered.

  3. templates folder: This folder holds the rest of your Shopify templates. It consists of:
    1. index.liquid: Displayed as the main index page of your shop.
    2. product.liquid: Each product will use this template to display itself.
    3. cart.liquid: Displays the current user’s shopping cart.
    4. collection.liquid: Displayed for collections of products.
    5. page.liquid: Displayed for any static pages that the shop may have created.
    6. blog.liquid: Displayed for any Shopify blogs for the shop.
    7. article.liquid: Displayed for any blog articles and includes a form for submitting comments.
    8. 404.liquid: Displayed for anytime the shop returns a 404.
    9. search.liquid: Displayed for shop search results.

As you might have guessed, each of these templates has access to different variables. For example, product.liquid has access to a product variable which contains the current product being displayed, blog.liquid has access to a blog variable, and index.liquid has access to all of them. If you’re interested in which variables you can use in which template, please review the Liquid documentation.

A Basic Skeleton to Get Started

The best thing about designing for Shopify is that you get to use all of the skills that you already have: HTML, CSS, JS, etc. The only roadblock in the process is becoming familiar with which Liquid variables are available in each template.

This is where Vision comes in.

Vision – Shopify in a Box

What is Vision?

Vision is a stand-alone application that allows you to create themes for Shopify stores on your local machine without having to sign up for a shop or setup a database or all that other geeky stuff.

What do I need to run Vision?

Vision comes complete with everything needed to run straight out of the box. If you’ve got a text editor and a web browser installed, you are ready to roll.

As if that wasn’t enough, Vision comes pre-loaded with Shopify's ready-made themes. Shopify has allowed people to use these themes as building blocks, so you can start with one of these existing themes as a base and expand upon on it!

Summary

Shopify is a fast growing e-commerce platform already with thousands of sellers looking to show off their products. Using Vision, you can hit the ground running and begin developing in no time. The first ten templates posted to Themeforest's Shopify category get an extra $100. So get started!

If you need more information about designing with Shopify, they have extensive documentation on their wiki. Check out The Shopify Theme Guide, Using Liquid, and Getting Started with Vision.

The Best Shopify Templates from ThemeForest....So Far!

  • Drifter

    Drifter

    "This sleek Shopify theme features clean lines and modern design accents that showcase your products. Custom jQuery lightboxes allow your products to be viewed in full detail."

    View Theme

  • Drifter

    Fancy Pink

    "A shopify theme with modern, fancy web 2.0 design."

    View Theme

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    Ryan March 6th

    Great post. Very interesting. Never knew about shopify.

    ( Reply )
  2. PG

    Snorri - Css March 6th

    This sounds COOL!
    if i have the time i will send in a theme for sure :D

    ( Reply )
  3. PG

    Rob MacKay March 6th

    I could never get Liquid to work… it installed fine but never ran, like it needed another component – although it only stated that OSX needed a seperate ruby devkit i think…

    ( Reply )
    1. PG

      Jason March 6th

      OSX 10.3 or older shipped with broken ruby. If you’re on 10.4 or 10.5 you should be able to run it without a problem.

      ( Reply )
    2. PG

      Jesse Storimer March 6th

      You don’t actually need to install Liquid to design a Shopify theme.

      If you just install Vision, it comes bundled with Liquid, Ruby, and everything you need to get started.

      ( Reply )
  4. PG

    Philo March 6th

    Great Article! :)

    ( Reply )
  5. PG

    Will March 6th

    I love it when a tutorial comes along just as you need it. Great introduction, I can’t believe I haven’t heard of Shopify before last week. Where have i been?

    ( Reply )
  6. PG

    Bjorn March 6th

    Nice. I was exploring different options for a client’s ecom solution and was tempted to give Shopify a trial run… (went Joomla + Virtuemart) With a little more familiarity now, I can see pulling the trigger next time.

    ( Reply )
  7. PG

    Jose March 6th

    How to user jQuery with Vision?

    I’ve been digging the source, but I don’t want to break it by changing the mounts.

    ( Reply )
  8. PG

    Jesse Storimer March 6th

    @Jose: Unfortunately Vision is in need of some love. It currently has a dependency on Prototype.

    Shopify plans to remove that dependency in the near future to make Vision javascript library agnostic, but for the time being you may want to try jQuery.noConflict( )?

    ( Reply )
  9. PG

    Mark Dunkley March 6th

    Very well written article Jesse

    ( Reply )
  10. PG

    Tetsuro March 6th

    Great article Jessee!

    ( Reply )
  11. PG

    crysfel March 6th

    nice post…. thank you ;)

    ( Reply )
  12. PG

    Sirwan March 6th

    Hey this exactly what we need at Netuts…. uncover things most people dont know about… I never knew about shopify and its a good thing Jesse made this tutorial.

    ( Reply )
  13. PG

    Raymond March 6th

    Be aware that clients can be reluctant about Shopify due to its extra fees. You might want to offer more coverage of up-and-coming open source solutions like Magento.

    ( Reply )
    1. PG

      Chris Simpson March 11th

      Yep Magento is a fantastic Ecommerce solution. As shopify is a ‘hosted solution’ its a different take on trading online..

      PS – Just keep away from OSCommerce. That should have died at least 5years ago, yet some clients are still so keen to find out more about such a crap system.

      ( Reply )
  14. PG

    daniel lopes March 6th

    Shopify is amazing and liquid is good to ( even, personaly, I don’t like sintax). Good tutorial ( and can be used in Mephisto ) ;) .

    ( Reply )
  15. PG

    aldrin March 6th

    it’s great to know about this, it’s my first time to hear this… sounds interesting

    ( Reply )
  16. PG

    michael March 6th

    quite expensive this shopify..

    monthly fee ok, but 2% of every transaction? this is way too expensive.
    better to sell this software for 500$ and we would be able to run it on our own server.

    i never would run a shop not on my own.

    ( Reply )
  17. PG

    Jose March 6th

    Hey Jesse, thanks for the reply. I didn’t know of such function.

    ( Reply )
  18. PG

    Sacha March 7th

    If you want to use jQuery with vision you can simply substitue the $ sign by “jQuery”, which is the full name of the function. So you’d use jQuery(”.myDiv”) instead of $(”.myDiv”).

    ( Reply )
  19. PG

    Alex Newman March 7th

    What about magento guys!! Let’s get a Magento Theme Tut and a bunch of magento themes on themeforest! I would say i’m pretty savvy at creating themes for open source software… I took on a magento project and had to switch to some other dumb shopping cart software – it was – overwhelming. I hate fail.

    ( Reply )
  20. PG

    will March 7th

    i like open source e-comerce packages but this is not ,

    anything that charges you a monthly fee is a product, considering you can down load oscommerce,magento and a few others

    then by a temp for around 180 dollors, this is a much better option than paying a monthly fee, and then paying for a theme

    also as soon as your shop gets busy your losing more cash due to fee’s and offering more products

    get a free open source e-comerce package, buy a book on it , build it

    ( Reply )
  21. PG

    kabarmadura March 8th

    great guys .. inspiring us
    thanks for share

    ( Reply )
  22. PG

    AdryDesign March 8th

    awesome tutorial

    ( Reply )
  23. PG

    Sandro March 9th

    Nice boots…!

    ( Reply )
  24. PG

    insic March 9th

    nice article. but the templating engine is pain in the ass. :)

    ( Reply )
  25. PG

    Steve March 9th

    Really good tutorial, but I agree with most about the transaction fees. A nice system but less profitable to use.

    ( Reply )
  26. PG

    Martyn March 9th

    I have been briefly looking into this as an e-commerce solution myself and experimenting with some open source platforms including magento. I signed up to shopify the other day so hopefully I can play around with the template and design to see how good it could potentially be.

    ( Reply )
  27. PG

    Ryan Gibson March 9th

    Great post. Great looking themes.

    ( Reply )
  28. PG

    michael March 10th

    it’s definitly a nice looking shop, clean navigation, easy to use.
    but there should be an option to buy a license and install on our own server.

    for me, a shop is something which i never would let on a unknown hoster. it’s a business, so i would like to host it on my own.

    i think there is no option for a backup, no control, the risk for dataloss is too high in my eyes.

    but, the tutorial is great, well written! keep going

    ( Reply )
    1. PG

      Chris Simpson March 11th

      By letting you host it on your own server they would be releasing their code to you, and this isnt an open-source project. If youre looking to host your own site, then consider Magento. its written in PHP too – so no scary RoR syntax ;)

      ( Reply )
      1. PG

        Soleone April 25th

        @Chris
        Lol, scary RoR syntax? I’m pretty sure Ruby/Rails projects usually look way more clean than PHP :D

        @michael
        The nice thing about this hosted solution is that Shopify takes care of the backups and hosting, so less headaches for you…

  29. PG

    Sribanta March 26th

    Its amazing.But not know how to install vision on Windows OS…..

    ( Reply )
  30. PG

    Tomas Matejka April 2nd

    I like this …

    ( Reply )
  31. PG

    Soleone April 25th

    Nice tutorial, just what was needed! Great job, Jesse!!

    ( Reply )
  32. PG

    iamkeir July 7th

    This is a good article, Jesse, and it’s appreciated – definitely stuff here to benefit new users of Shopify’s theming system… but I think the title/intro is a bit misleading – it implies you’re going to have built a theme by the end of the tutorial, when really it’s a quick glance at the anatomy of a Shopify theme and more of a ‘getting started’ guide – the summary especially seems to leap out before we’ve really got our hands dirty.

    No real harm in that, though – just some constructive criticism :)

    ( Reply )
  33. PG

    mofo July 20th

    I second that, iamkeir.

    ( Reply )
  34. PG

    Anton August 25th

    I’ve been using Shopify for almost a year now and I can say that it is a very reliable product. The templates they offer for free are really unattractive, but you can buy a 3rd party one for around 80 bucks and really go to town customizing it if you have decent CSS skills.

    Obviously Shopify’s main drawback is the monthly fees which seem are a bit too high.

    ( Reply )
  35. PG

    jasdeep September 3rd

    Hello How to add new field to a form For example:I want to Add a field to the ordering process where a trade customer has to enter their unique trade customer ID reference number and make this a mandatory field .I want to do this in shoping cart page.How to do this?Help

    ( Reply )
  36. PG

    Lisa October 22nd

    Great post. I’m currently trying to figure out how to create a giveaway within our site (I don’t really know html, I’m self taught) can you advise?

    http://www.hazelandharlow.com

    We’ve been with Shopify since 08/09

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    October 22nd