3

I 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 foo, {foo:total_rows} returns 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>

{foo}
    <h3>loop field_total_rows {foo:field_total_rows}</h3>
    <h3>loop total_rows {foo:total_rows}</h3>
{/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?
2
  • This may be a bug re: no count when there's only one row, but field_total_rows is not available in the shortcut syntax (see docs) - which makes sense, because it only exists to ignore any parameters you've set on the tag pair. Sep 9 '13 at 13:49
  • I have already submitted this as a bug to the EE bugtracker. Hopefully someone will address this problem. Sep 10 '13 at 2:17
2

If your conditional is checking if it is > 0 this would work fine as a replacement:

{if foo:total_rows != ""}
     You have more than 1 row.
{if:else}
     You have 1 row.
{/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.