Step 8: Template Logic Outline

The Template itself contains sections for 1) presenting the list and item contents, and 2) displaying forms for the creation of more lists and items.

For developmental balance I'm compelled now to complete our end-to-end infrastructure, with a first draft of our Django template index.html, based on the assumptions so far:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>Passing Keys</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >

</head>

<body>

<a href="/"><font size="+3"><b>Passing Keys</b></font></a>

<br> <br><br>

{% if list_form %}

{# list_form #}

{% else %}

<a href="/list_form/">Create a List</a><br><br>

{% endif %}

{% for list in lists %}

{{ list.name }}<br>

{% for item in list.items %}

{{ item.name }}

{% endfor %}

{% if item_form %}

{% ifequal list.key list_key %}

{# item form #}

{% else %}

<a href="/item_form/{{ list.key }}/#form"> Create an item </a><br>

{% endifequal %}

{% else %}

<a href="/item_form/{{ list.key }}/#form">Create an item </a>

{% endif %}

{% endfor %}

</body>

</html>

Clearly, the understanding behind the smooth encoding of this template outline would require additional sequences to explain. I'm sticking with fairly large morphological changes in this sequence, but many other worthwhile sequences, and approaches, remain unexplored. For example, I could have started to create pieces of the template in earlier steps.

Note that from a user perspective, a web implementation pathway or cycle begins here. I start with the "Create" links. Developers tend to follow this cycle, this mini sequence, to put themselves in the user's shoes, and to provide a reality check, during live webapp development: create links -> create form -> entity storage -> render data. It's a very natural cycle, and so common that, if you watch development in time-lapse, it'll make you dizzy. You can see it in public programming events like the Google App Engine Introduction. I did it too, and it's reflected here. It's useful both in exploratory development and recapitulation.

What did I know at this "template logic outline" stage? With an evangelical passion for the Model-View-Controller pattern, Django templates attempt to force logical constraints on the developer, literally, by forcing as much logic as possible out of the template. The result is a few extra conditional tags here and there -- for example, a test for item_form and a separate "equal" test for the desired list_key, resulting in a duplicate "Create an item" link in the template.