I'm just playing around with TurboGears at the moment, evaluating it
for use in a more substantial project. I've got a table with lots of
rows in it and am displaying them in pages of 10. When presenting links
to the previous and next page I've found myself doing this:

  <div py:def="paginate_links(paginator, name)" class="toolbar">
    <?python
    page_var = name + "_page"
    ?>
    <span py:if="paginator.has_previous">
      <a href="?${page_var=paginator.next}">&lt;&lt; earlier</a>
    </span>
    <span py:if="not paginator.has_previous">
      &lt;&lt; earlier
    </span>
    |
    <span py:if="paginator.has_next">
      <a href="?${page_var=paginator.next}">later >></a>
    </span>
    <span py:if="not paginator.has_next">
      later >>
    </span>
  </div>

It feels dirty typing everything twice to duplicate the
(understandable) lack of something like py:else. Feelings like this are
usually accompanied by me having failed to grasp something fairly
crucial.

So how would you do it? I thought of making a normal Python function
that creates the links, but once I start producing XML outside of a kid
template wouldn't I lose the benefit of knowing that my XHTML is well
formed?

Graham

Reply via email to