Lets Build a Shopify Theme

Let’s Design a Shopify Theme

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.

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.


Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.search4toffee.co.uk Ryan

    Great post. Very interesting. Never knew about shopify.

  • Snorri – Css

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

  • http://www.alteredaspect.info Rob MacKay

    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…

    • http://www.jasonstanbery.com Jason

      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.

    • http://www.jstorimer.com Jesse Storimer
      Author

      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.

  • http://www.philohermans.nl Philo

    Great Article! :)

  • http://www.createatwill.com Will

    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?

  • http://smilingdesigner.com Bjorn

    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.

  • Jose

    How to user jQuery with Vision?

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

  • http://www.jstorimer.com Jesse Storimer
    Author

    @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( )?

  • Mark Dunkley

    Very well written article Jesse

  • Tetsuro

    Great article Jessee!

  • http://www.quizzpot.com crysfel

    nice post…. thank you ;)

  • http://www.swaymedia.com Sirwan

    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.

  • http://needmorenotes.com/ Raymond

    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.

    • Chris Simpson

      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.

  • http://www.areacriacoes.com.br daniel lopes

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

  • http://www.aldrinponce.com aldrin

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

  • http://www.zitrox.com michael

    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.

  • Jose

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

  • http://www.sachagreif.com Sacha

    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”).

  • http://ndesignlab.com Alex Newman

    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.

  • will

    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

  • http://www.kabarmadura.com kabarmadura

    great guys .. inspiring us
    thanks for share

  • Pingback: Daily Links | AndySowards.com :: Professional Web Design, Development, Programming, Hacks, Downloads, Math and being a Web 2.0 Hipster?

  • AdryDesign

    awesome tutorial

  • http://www.toldesign.nl Sandro

    Nice boots…!

  • http://blog.insicdesigns.com insic

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

  • http://www.mindred.co.uk Steve

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

  • http://www.crearedesign.co.uk Martyn

    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.

  • http://www.search4toffee.co.uk Ryan Gibson

    Great post. Great looking themes.

  • Pingback: Best of the Web: February - NETTUTS

  • http://www.zitrox.com michael

    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

    • Chris Simpson

      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 ;)

      • http://soleone.wordpress.com Soleone

        @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…

      • http://www.pixelapes.com Alex Leonard

        That’s all well and good, but have you looked at Magento templating? Never before has anything confounded me so much. It’s a nightmare to work with.

  • Sribanta

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

  • http://www.tomasmatejka.net Tomas Matejka

    I like this …

  • http://soleone.wordpress.com Soleone

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

  • http://iamkeir.com iamkeir

    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 :)

  • mofo

    I second that, iamkeir.

  • Pingback: E-Commerce Web Design Toolbox

  • http://www.soyaromas.com Anton

    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.

  • http://www.sainijasdeep.com jasdeep

    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

  • http://www.hazelandharlow.com Lisa

    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

  • http://www.papicc.com/news.html alan p

    Someone needs to build a “theme generator” where you prep your psd accordingly, upload it, then get a theme back you can upload to shopify . . . small charge would be tenable . . .
    I saw Shopify in action, and loved it, but had no idea they have zero support and you have to find coders to help . . . jeez . . .

  • http://adealy.com Steven

    Shopify is a powerful platform and easy to use. We have Beta invites for your readers for our Shopify app to run Deal of days. The popularity of Woot on your own e-com site. Go to http://adealy.com and enter NETPLUS

  • http://www.jeronone.com Sandeep

    Thanks Admin for the tutorial.

    But, I see, shopify’s latest features are not supported by vision. So, they recommend some other theme generator using Meeech’s Textmate Bundle.

    They have instructions on their website on how to use it. but very limited. I am a windows user. couldn’t get hold on it.

    Can you please give an update on Meeech’s Textmate Bundle?

  • http://www.derby-webdesign.co.uk Kevin

    I knew you guys would have a great article about this. I’ve just started using Shopify and really appreciate your help. Thanks again.

  • http://davidslv.com David

    Yap, is great to have some information, but for example, Vision is no longer supported by shopify.

    http://wiki.shopify.com/Vision

    • http://www.derekpadula.com Derek Padula

      You can still download Vision through Github.

      It was frustrating to find because they don’t point to it anywhere on the Shopify site, and the vision.shopify.com link was down when I tried. Google came to the rescue by pointing to Github.

  • Pingback: Shopify 入门 (英文) | 南龙的小站

  • http://www.minerskinz.com/ Miner

    I am graphic designer like to design premium themes for shopify, any coder like to partner with me? we share the revenue equal.