Extension for Object #table

Hello together.

Yesterday I had to template an inline table with thead and tbody.

So I checked the documentation if there ist something like #table.firstRow ist available or #table.rowNumber or something like that.

Unfortunately not. Smiley Sad

#table.lastRow is available.

I coded a counter to check for the table head, so this problem is solved for now.

But is it possible to extend the systemobject #table by the data field rowNumber or firstRow or something like that?

Greetz

10 Comments
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

The system object #cell has (among others) the boolean properties firstRow and lastRow.

I think extending #table would not server your need (#table.lastRow delivers the index of the last row).

rbitdd
Returning Responder

That's right. But when I am in the depth of #cell I have no #row.

So I have to code something like

<thead>

<tr><th>my header</th></tr>

</thead>

<tbody>

<tr><td>my content</td></tr>

</tbody>

into my #cell and I think that is not an recommendable / handy way.

Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Ok, so you ar missing a #row system object. This name is already used for the rows of content selects.

In the format template for 'Table Row' you can use #global.context instead - e.g. #global.context.firstRow (boolean).

But you must still use an $CMS_IF(..)$ in the format template 'Table Cell' to distinguish between the tags th and td.

rbitdd
Returning Responder

Sorry for the mistake to #row.

Ok so far. Thanks for the information.

I solved that problem with a counter. My counter counts the rows, so i can check in which row I am.

Here is my code. I hope you understand my problem better then:

$CMS_IF(!isSet(counter))$

  $CMS_SET(counter,0)$

$CMS_END_IF$

$CMS_IF(counter == 0 && st_table_head)$

   <thead>

$CMS_ELSE$

  $CMS_IF(counter == 0 || st_table_head && counter == 1)$

     <tbody>

  $CMS_END_IF$

$CMS_END_IF$


<tr>$CMS_VALUE(#content)$</tr>


$CMS_IF(counter == 0 && st_table_head)$

  </thead>

$CMS_END_IF$

$CMS_IF(#table.lastRow)$

  </tbody>

$CMS_END_IF$

$CMS_SET(counter,counter+1)$

I could replace the "counter == 0" by #global.context.firstRow, but I still need the counter for "counter == 1" to check for the tbody in case of using thead.

Or is there a #global.context.secondRow? I can't imagine that.

Peter_Jodeleit
Crownpeak employee
Crownpeak employee

rbitdd wrote:

Or is there a #global.context.secondRow? I can't imagine that.


                   

You could use #global.context.row == 1.

$CMS_IF(#table.lastRow)$

  </tbody>

$CMS_END_IF$

Cannot imagine that this code is working,  #table.lastRow is a numeric value, not a boolean.

rbitdd
Returning Responder

This is exactly what I was looking for. In a different context, but exactly what I was looking for.

You were right the part with #table.lastRow didn't work Smiley Sad haven't seen that before. thanks for the hint.

Now my code looks like this (without counter Smiley Wink)

$CMS_IF(#global.context.firstRow && st_table_head)$

  <thead>

$CMS_ELSE$

  $CMS_IF(#global.context.firstRow || st_table_head && #global.context.row == 1)$

    <tbody>

  $CMS_END_IF$

$CMS_END_IF$


<tr>$CMS_VALUE(#content)$</tr>


$CMS_IF(#global.context.firstRow && st_table_head)$

  </thead>

$CMS_END_IF$

$CMS_IF(#table.lastRow == #global.context.row)$

  </tbody>

$CMS_END_IF$

gockel
Crownpeak employee
Crownpeak employee

So, the remaining feature request is a short cut #row for the table row render context !?!

rbitdd
Returning Responder

That would be nice! Smiley Happy

With properties like: lastRow, firstRow as boolean and currentRow as integer.

Greetz!

Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Perhaps the name should be better #tableRow or #trow or something like this. To distinguish it from the content rendering variable name...

Peter_Jodeleit
Crownpeak employee
Crownpeak employee

So, the remaining feature request is a short cut #row for the table row render context !?!

This internal id for this feature is #94459.

The context name will be #tr.

Current row number will be available with #tr.row, #tr.lastRow, and #tr.firstRow will both deliver a boolean.

The feature is scheduled for version 4.2.R4.