[Zope-dev] <dtml-in> how do I get count of records in sequence? (aka batch-size)

Michel Pelletier michel@digicool.com
Mon, 17 Apr 2000 10:03:48 -0700


Brad Clements wrote:
> 
> I want to be able to do something like this:
> 
> <dtml-in "GetDB()[Table][Indice][Rec].fetchall()">
> <dtml-with "_['sequence-item']">
> <dtml-if "_['sequence-size'] == 1">
> <dtml-var  "tableFromView(URL=URL0)">
> <dtml-else>
> <dtml-var  "tableFromView(viewName='DefaultLocatorView',URL=URL0)">
> </dtml-if>
> </dtml-with>
> </dtml-in>

First off, the <dtml-with "_['sequence-item']"> is superfluous, the
<dtml-in> tag automagically pushes sequence-item on the top of the
namespace stack.

Second, there is the python builtin function _.len() that you can use to
determine the size of a sequence (untested)::

  <dtml-let sequence="whatever()">
    <dtml-in sequence>
      <dtml-if "_.len(sequence) == 1">
        one
      </dtml-in>
    </dtml-in>
  </dtml-let>

The <dtml-let> is useful because it caches the possibly expensive
whatever() operation into a 'local' variable.

-Michel