Entries published on May 24, 2006

1 entry published on this date. See also: all entries published in May 2006, latest entries.

Why templating languages aren’t a bad idea

Before I get into any meaty details, a quick question. You have a dynamic, database-driven web application and you’re ready to sit down and bang out its HTML output. One part of one page will be an ordered list containing comments left by visitors. You have the following choices for doing this:

Option A:

<ol class="comments">
{% get_comment_list %}
{% for comment in comment_list %}
<li>{{ comment }}</li>
{% endfor %}

Option B:

item = page.new_content_element('ol')
item.class = 'comments'
for comment in db.get_post(post_id)['comments']:
    c = item.new_subelement('li')
    c.contents ...

Entry published May 24, 2006. Read full entry.