template with alternating currentblock entries

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bettyann@campbell.com

    template with alternating currentblock entries

    i am using templates via HTML_Template_I T to create a table from the
    results of a mysql query. i wanted to change the background image of
    alternating rows in the table. i thought i could do this by defining
    two different blocks in the template file and setting the current block
    based on ( $thisRowNum % 2 ).

    when the final table is displayed, all the "even" rows are displayed
    before all the "odd" rows. in other words, the rows are not
    interleaved. how can i get the rows to display properly alternating?

    --------------------------
    my template file 'searchResults. html' contains:

    <table width="100%" border="0" cellpadding="0" cellspacing="5" >
    <!-- BEGIN ENTRY_EVEN -->
    <tr><td rowspan="3">{AU THOR}</td></tr>
    <!-- END ENTRY_EVEN -->

    <!-- BEGIN ENTRY_ODD -->
    <tr><td rowspan="3" class="shadeDar ker2">{AUTHOR}</td></tr>
    <!-- END ENTRY_ODD -->
    </table>

    --------------------------
    my PHP code in 'searchAction.p hp' contains:

    $template = new HTML_Template_I T( "./templates" );
    $template->loadTemplatefi le( "searchResult.h tml", true, true );

    $thisRowNum = -1;
    while ( $row = mysql_fetch_arr ay( $result )) {
    $thisRowNum++;
    if ( $thisRowNum % 2 ) {
    $currBlock = "ENTRY_ODD" ;
    } else {
    $currBlock = "ENTRY_EVEN ";
    }
    print "thisRowNum = $thisRowNum; currBlock = $currBlock; author[color=blue][color=green]
    >>{$row["author"]}<< <br>\n";[/color][/color]

    $template->setCurrentBloc k( $currBlock );
    $template->setVariable( "AUTHOR", $row["author"] );
    $template->parseCurrentBl ock();
    } // end while mysql_fetch_arr ay

    $template->parse();
    $template->show();

    --------------------------
    which produces this output:

    thisRowNum = 0; currBlock = ENTRY_EVEN; author >>Boff, Leonardo<<
    thisRowNum = 1; currBlock = ENTRY_ODD; author >>Galilea, Segundo<<
    thisRowNum = 2; currBlock = ENTRY_EVEN; author >>Manning, Brennan<<
    thisRowNum = 3; currBlock = ENTRY_ODD; author >>Nolan, Albert<<
    thisRowNum = 4; currBlock = ENTRY_EVEN; author >>Segundo, Juan Luis<<

    --------------------------
    but the table is shown with the authors in the following order:

    (ENTRY_EVEN) Boff, Leonardo
    (ENTRY_EVEN) Manning, Brennan
    (ENTRY_EVEN) Segundo, Juan Luis
    (ENTRY_ODD) Galilea, Segundo
    (ENTRY_ODD) Nolan, Albert

    is there some buffer-flushing issue here?

    thanks - bettyann

  • rush

    #2
    Re: template with alternating currentblock entries

    <bettyann@campb ell.com> wrote in message
    news:1112064826 .226199.91990@g 14g2000cwa.goog legroups.com...[color=blue]
    > i am using templates via HTML_Template_I T to create a table from the
    > results of a mysql query. i wanted to change the background image of
    > alternating rows in the table. i thought i could do this by defining
    > two different blocks in the template file and setting the current block
    > based on ( $thisRowNum % 2 ).[/color]

    for what is worth here is an example how it is done in TT:



    rush
    --




    Comment

    • bettyann@campbell.com

      #3
      Re: template with alternating currentblock entries

      rush wrote:[color=blue]
      > for what is worth here is an example how it is done in TT:
      > http://www.templatetamer.org/index.p...ingListExample[/color]

      thanks, rush, for pointing me in the right direction. i needed to nest
      both blocks in a "super-block". then, after selecting and parsing each
      block, i had to select and parse the "super-block". this makes sense
      since all blocks group together -- all the "super-blocks" group
      together regardless of the "sub-blocks" they contain. this allows my
      alternating rows.

      --------------------------
      my template file 'searchResults. html' contains:

      <table width="100%" border="0" cellpadding="0" cellspacing="5" >
      <!-- BEGIN ENTRY -->
      <!-- BEGIN ENTRY_EVEN -->
      <tr><td>{AUTHOR }</td></tr>
      <!-- END ENTRY_EVEN -->

      <!-- BEGIN ENTRY_ODD -->
      <tr><td class="shadeDar ker2">{AUTHOR}</td></tr>
      <!-- END ENTRY_ODD -->
      <!-- END ENTRY -->
      </table>

      --------------------------
      my PHP code in 'searchAction.p hp' contains:

      $template = new HTML_Template_I T( "./templates" );
      $template->loadTemplatefi le( "searchResult.h tml", true, true );

      $thisRowNum = -1;
      while ( $row = mysql_fetch_arr ay( $result )) {
      $thisRowNum++;
      if ( $thisRowNum % 2 ) {
      $currBlock = "ENTRY_ODD" ;
      } else {
      $currBlock = "ENTRY_EVEN ";
      }

      // set current block to "ENTRY_EVEN " or "ENTRY_ODD"
      $template->setCurrentBloc k( $currBlock );
      $template->setVariable( "AUTHOR", $row["author"] );
      $template->parseCurrentBl ock();

      // set current block to 'super-block' "ENTRY"
      $template->setCurrentBloc k( "ENTRY" );
      $template->parseCurrentBl ock();

      } // end while mysql_fetch_arr ay

      $template->parse();
      $template->show();

      thanks for the help - bettyann

      Comment

      Working...