My first Grok tutorial
http://grok.zope.org/documentation/t...es-layers/tutorial-all-pages3rd of June 2008
This is my first published full Grok tutorial which I'm quite proud of. In my view it manages to keep things very simple and easy to follow even if you're not a senior Grok developer and shows a very powerful pattern.
The gist of the tutorial is to set up a basic simple web site in Grok that uses templates and macros to avoid repeating yourself. Then it extends it by adding a web design layer dedicated for mobile phones which have smaller screens and usually much lower bandwidth. Unlike more trivial solutions, this solution does not have any crazy things like you sometimes see like this:
<? if current_url.startswith('http://mobile.') ?>
<link href="mobile.css" />
<? else ?>
<link href="mobile.css" />
<? fi ?>
The approach taken in this tutorial to the mobile web problem is to first of all replace the main template that defines the header and footer and all the templates that depends on this main template don't have to change since they refer to the main template in an agnostic way unlike a Django solution which would look something like this:
{% if in_mobile %}
{% include "mobile.html" %}
{% else %}
{% include "base.html" %}
{% endif %}
In Grok you don't really have "templates". Instead you have something called "views" which in turn uses templates sometimes to render the HTML, XML or PDF. These views are proper object rather than what sometimes feels like functions or methods to model classes.
The tutorial shows two approaches to making the decision between serving the mobile layer or the default layer. One is to use a hardcoded keyword in the URL (masked by a virtual host setting) and one is to use business logic to make the switch there and then. What you chose depends on your requirements. Both have advantages and disadvantages. Hopefully my tutorial will make this clear.
Thank you all the guys at the Grokkerdam sprint in March 2008 who helped me understand how layers work. You (g)rock!
That was nice. Maybe I'll learn Grok too :)