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 %}

Thanks to C8N on #django for correcting an error in Django template code. :)
I think that what it shows is that Django and Liguid both resemble the Smarty templating engine in PHP . :-p
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.
What do you mean by template inheritence? Templates being able to pass a sub-template data?
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.
Django’s template engine was indeed the inspiration for liquid. Its easy to parse and aestetically pleasing syntax.