Shopify templates resemble Django

Posted by Jeremy Voorhis Sat, 01 Oct 2005 01:06:00 GMT

A colleague on IRC recently brought Shopify to my attention. Shopify looks to be a tidy hosted service for running your own shopping cart, complete with through-the-web template customization. Since ERb might not be appropriate for templates that users create, they also developed a template language called liquid to allow safe customization of their users’ shops. Surprisingly, it strongly resembles Django’s template language.

Here is their sample Liquid template:


{% if products == empty %}
  <p>There are no products in this area</p>
{% else %}

  {% foreach product in products %}
    <div class="product">
      <h2>{{ product.title }}</h2>

      <div class="product-image">
        {{ product.image -> thumbnail }}
      </div>

      <div class="product-description">
        {{ product.description }}
      </div>
    </div>
  {% end %}

{% end %}

Rewritten for Django:


{% if not products %}
  <p>There are no products in this area</p>
{% else %}

  {% foreach product in products %}
    <div class="product">
      <h2>{{ product.title }}</h2>

      <div class="product-image">
        {{ product.image | thumbnail }}
      </div>

      <div class="product-description">
        {{ product.description }}
      </div>
    </div>
  {% endfor %}

{% endif %}

Comments

  1. Jeremy said about 1 hour later:

    Thanks to C8N on #django for correcting an error in Django template code. :)

  2. Robby Russell said about 3 hours later:

    I think that what it shows is that Django and Liguid both resemble the Smarty templating engine in PHP . :-p

  3. Jeremy said about 3 hours later:

    Perhaps so. I would guess that Django is the most sophistocated of the three, since it also supports the concept of template inheritence, which is quite delicious. I am told that was carried over from Cheetah, but I wouldn’t know.

  4. Robby Russell said about 5 hours later:

    What do you mean by template inheritence? Templates being able to pass a sub-template data?

  5. Jeremy said about 9 hours later:

    http://www.djangoproject.com/documentation/templates/

    It’s simple, and it resembles layouts in Rails, but I find it to be quite effective in practice.

  6. tobi said about 22 hours later:

    Django’s template engine was indeed the inspiration for liquid. Its easy to parse and aestetically pleasing syntax.

Trackbacks

Use the following link to trackback from your own site:
http://www.jvoorhis.com/articles/trackback/35

(leave url/email »)