alternating colors based on sequence-index of outer loop
I have a folder called Sections that is filled with Section instances. Each Section contains a variable number of students, and I want all the students in a given section to have the same row color in my table, with sections alternating colors. I have nested dtml-in loops over the sections and students in each section, and want the rows of my table to alternate in batches depending on whether the outer loop is even or odd. Basically, I need to do a dtml-let in the outer loop that the inner loop will access, but am having trouble with the syntax. Here is some example dtml with pseudo code to set the default_color <dtml-in expr="Sections.objectValues('Section')" mapping> <dtml-if sequence-even> default_color="gray" <dtml-else> default_color="white" </dtml-if> <dtml-in expr="_['sequence-item'].objectValues('Student')" mapping> <tr default_color> ..Fill in the row.. </tr> </dtml-in> </dtml-in> Thanks for any help, John Hunter
John Hunter wrote:
I have a folder called Sections that is filled with Section instances. Each Section contains a variable number of students, and I want all the students in a given section to have the same row color in my table, with sections alternating colors.
I have nested dtml-in loops over the sections and students in each section, and want the rows of my table to alternate in batches depending on whether the outer loop is even or odd. Basically, I need to do a dtml-let in the outer loop that the inner loop will access, but am having trouble with the syntax.
Here is some example dtml with pseudo code to set the default_color
<dtml-in expr="Sections.objectValues('Section')" mapping> <dtml-if sequence-even> default_color="gray" <dtml-else> default_color="white" </dtml-if> <dtml-in expr="_['sequence-item'].objectValues('Student')" mapping> <tr default_color> ..Fill in the row.. </tr> </dtml-in> </dtml-in>
Thanks for any help, John Hunter
There is a prefix attribute to dtml-in, which allows you to name the different sequence iterators.For details see http://www.zope.org/Members/michel/ZB/AppendixA.dtml cheers hans ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
"hans" == hans <hans@beehive.de> writes:
hans> There is a prefix attribute to dtml-in, which allows you to hans> name the different sequence iterators.For details see hans> http://www.zope.org/Members/michel/ZB/AppendixA.dtml cheers Thanks, that is exactly what I am looking for. I am, however, having trouble using the sequence-var-variable syntax with prefixes from the outer loop. Eg, section_var_id gives a key error in the example below <dtml-in expr="Sections.objectValues('Section')" prefix="section"> <dtml-in expr="_['section_item'].objectValues('Student')" prefix="student" sort="last_name"> <tr> <dtml-if student_start> <th rowspan=<dtml-var student_length>><dtml-var section_var_id></th> </dtml-if> ...[snip]... </tr> </dtml-in> </dtml-in> although I can still access that value with <dtml-var expr="_['section_item'].id"> Am I missing the syntax, or is there a problem using prefixes with the sequence-var-variable syntax? Thanks for your help, John Hunter Zope 2.5.1b1
John Hunter wrote:
"hans" == hans <hans@beehive.de> writes:
hans> There is a prefix attribute to dtml-in, which allows you to hans> name the different sequence iterators.For details see hans> http://www.zope.org/Members/michel/ZB/AppendixA.dtml cheers
Thanks, that is exactly what I am looking for. I am, however, having trouble using the sequence-var-variable syntax with prefixes from the outer loop. Eg, section_var_id gives a key error in the example below
<dtml-in expr="Sections.objectValues('Section')" prefix="section">
<dtml-in expr="_['section_item'].objectValues('Student')" prefix="student" sort="last_name"> <tr> <dtml-if student_start> <th rowspan=<dtml-var student_length>><dtml-var section_var_id></th> </dtml-if>
...[snip]... </tr> </dtml-in> </dtml-in>
although I can still access that value with <dtml-var expr="_['section_item'].id">
Am I missing the syntax, or is there a problem using prefixes with the sequence-var-variable syntax?
yes. there is no variable named "var_id" :-) there is an attribute "id" to zope objects, usually accessed by object.id (although the (newer) getId() method is recommended). the object whose id you want is named "section_item". inside a dtml-in, on each iteration this (and all the iteration infos) are automagically pushed (and poped) onto the namespace "_", so there is no need to "_['section_item']", section_item alone will do. how about <dtml-var expr="section_item.id"> ? ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
Try the following <dtml-in expr="Sections.objectValues('Section')" mapping> <dtml-if sequence-even> <dtml-call "REQUEST.set ('dcolor', '#EEEEEE')"> <dtml-else> <dtml-call "REQUEST.set ('dcolor', '#DDDDDD')"> </dtml-if> <dtml-in expr="_['sequence-item'].objectValues('Student')" mapping> <tr bgcolor=<dtml-var dcolor>> ..Fill in the row.. </tr> </dtml-in> </dtml-in> I hope you wrote <dtml-in> loops with no mistakes :) I corrected only the row coloring code part. -- Dmitry
I have a folder called Sections that is filled with Section instances. Each Section contains a variable number of students, and I want all the students in a given section to have the same row color in my table, with sections alternating colors.
I have nested dtml-in loops over the sections and students in each section, and want the rows of my table to alternate in batches depending on whether the outer loop is even or odd. Basically, I need to do a dtml-let in the outer loop that the inner loop will access, but am having trouble with the syntax.
Here is some example dtml with pseudo code to set the default_color
<dtml-in expr="Sections.objectValues('Section')" mapping> <dtml-if sequence-even> default_color="gray" <dtml-else> default_color="white" </dtml-if> <dtml-in expr="_['sequence-item'].objectValues('Student')" mapping> <tr default_color> ..Fill in the row.. </tr> </dtml-in> </dtml-in>
Thanks for any help, John Hunter
participants (3)
-
Dmitry Litovchenko -
hans -
John Hunter