ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Grid {field:total rows} is not returning correct value

September 08, 2013 10:12pm

Subscribe [1]
  • #1 / Sep 08, 2013 10:12pm

    arvinsim

    23 posts

    have a field(let’s call it foo) with the Grid Fieldtype.

    I have conditional to check if foo is greater than 0 or not

    Now here is the problem. It seems to me that when I only have 1 row in the foo, {foo:total_rows} return nothing.

    I tried adding another row. This time {foo:total_rows} returns 2. It is the same thing with 3, 4, etc. Basically anything greater than 1.

    This shouldn’t be the case. If there is only 1 row, it should return 1.

    I would to point out that the foo field is in a Channel with multiple Grid fieldtypes. It also has a relationship fieldtype for one of its columns.

    I have another Grid field in that channel but without a realationship fieldtype for one of its columns. It is working correctly.

    Any idea why this is happening?

    UPDATE:

    Tried out this code

    <h3>field_total_rows {foo:field_total_rows}</h3>
    <h3>total_rows {foo:total_rows}</h3>
    
    <p>{foo}<br />
        </p><h3>loop field_total_rows {foo:field_total_rows}</h3>
    <p>    </p><h3>loop total_rows {foo:total_rows}</h3>
    <p>{/foo}

    Output when the field contains only 1 row

    field_total_rows
    total_rows
    loop field_total_rows 1
    loop total_rows 1

    Output when the field contains 2 rows

    field_total_rows
    total_rows 2
    loop field_total_rows 2
    loop total_rows 2
    loop field_total_rows 2
    loop total_rows 2

    - Does this mean that the total_rows and field_total_rows can only be accessed inside the loop?
    - Why does the total rows variable only appear if it is greater than 1?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases