Re: [Zope] Checking sequence-index using dtml-if
Thanks. Could you please help me understand the syntax of the statement you suggested? Specifically, this portion ZSQLMethod()[:3] Additionally, with this method, is there a way to process all records starting with a certain number until eof()? Thanks again for your help. At 08:57 AM 2/21/2001 +1100, you wrote:
On Monday 19 February 2001 16:56, John Morton wrote:
On Sun, 18 Feb 2001 21:57:27 -0600 Jeff Hotz <jeff@hotz.net> wrote:
I only want to operate on the first 3 records returned in the ZSQL_select_images.
I thought that a dtml-if test would do it based on the dtml-var sequence-index but I'm not having any luck.
Any suggestions on either my logic or the implementation of it?
Any help you can offer will be greatly appreciated. Thanks.
<dtml-in ZSQL_select_images> <dtml-if expr="'<dtml-var sequence-index>' < 3">
You can't embed a dtml statement inside another like this .I believe this says 'if the string '<dtml-var sequence-index>' is less than three', which is not what you want. What you probably did was to start by using sequence-index and had zope complain about it. What you should try is this:
<dtml-if expr="_['sequence-index'] < 3">
Use the dtml namespace lookup notation when ever you need to use an attribute name with a '-' in it, inside an expression. And submit it as a bug to the collector until the DC folk give in and include '_' equivalents to all the attributes that use dashes :-)
Whilst this is a good answer in that it corrects a misunderstanding in the users understanding of DTML, there is, imho, a better solution to the actual problem. And that is to slice the returned list from the ZSQL method.... something like:
<dtml-in expr="ZSQL_select_images()[:3]"> ... </dtml-in>
will only iterate over the first 3 elements in the list.
John
jeff@hotz.net www.hotz.net
On Wednesday 21 February 2001 14:02, Jeff Hotz wrote:
Thanks.
Could you please help me understand the syntax of the statement you suggested?
Specifically, this portion ZSQLMethod()[:3]
Additionally, with this method, is there a way to process all records starting with a certain number until eof()?
OK. Starting with the line: <dtml-in expr="an_sql_method()[:3]"> (this is exactly the same as <dtml-in "an_sql_method()[:3]"> but is more clear to the human that it's an expression.) The dtml-in portion, as you know, means "iterate over the elements in this list". expr="" means 'evaluate this string as Python' an_sql_method() is fairly obvious... and since it returns a List, you can 'slice' the list, using [:3], which means "the first 3 elements". If you wanted to start with the fourth, and continue on, you would use: an_sql_method()[4:] Note, this is not the same as: an_sql_method()[4] which would return ONLY the fourth element. This is standard Python syntax, which is fairly clearly documented in the Python language documentation.
Thanks again for your help.
Have a better one, Curtis Maloney.
participants (2)
-
Curtis Maloney -
Jeff Hotz