1

I'm getting some odd behaviour from my Grid field in the template (unless I'm misunderstanding the Grid docs). I have a custom Grid field used for placing images (columns are file, alt text and caption). In one of my channel entries I have three images set via this field. The following template code displays all three images, as expected:

{my_image_grid}
<figure>
    <img src="{my_image_grid:file}" alt="{my_image_grid:alt}">
    <figcaption>{my_image_grid:caption}</figcaption>
</figure>
{/my_image_grid}

And, also as expected, this code displays only the contents of the first row of the grid field:

{my_image_grid row_id="1"}
    <figure>
        <img src="{my_image_grid:file}" alt="{my_image_grid:alt}">
        <figcaption>{my_image_grid:caption}</figcaption>
    </figure>
{/my_image_grid}

However, when I try to display all rows other than row 1, with the following:

{my_image_grid row_id="not 1"}
    <figure>
        <img src="{my_image_grid:file}" alt="{my_image_grid:alt}">
        <figcaption>{my_image_grid:caption}</figcaption>
    </figure>
{/my_image_grid}

I get just the first row again. Just the first row is also displayed if I try to display a specific row other than 1:

{my_image_grid row_id="3"}
    <figure>
        <img src="{my_image_grid:file}" alt="{my_image_grid:alt}">
        <figcaption>{my_image_grid:caption}</figcaption>
    </figure>
{/my_image_grid}

Can anyone else verify this behaviour before I report it as a bug? Or am I doing something wrong (eg. misunderstanding how rows are ID-ed)? This is EE 2.7.2.

Thanks.

0

It seems row_id works on the database table ID, not on the row number.
Use the offset parameter and {gridfield:count} variable instead.

 

In my opinion it's a bug, because if you only provide one row, the grid-parser will not take "not" into account somehow. To circumvent this bug add a zero in front so that it 'thinks' it has multiple entries. ``` row_id="not 0|1" ```

(ps. bug filed: https://support.ellislab.com/bugs/detail/19852 )

| improve this answer | |
  • Hmm. Adding the zero as you suggest seems to bypass the row_id parameter entirely, because now I'm getting all three rows again, not just rows 2 and 3 as I should. It definitely appears to be a bug, but it goes farther than just the 'not' part of the parameter, as demonstrated by the fact that row_id="3" doesn't work either (see the last code example in my original post). I'll add a comment to your bug report, GDmac, with some extra info from my own experiences. – RickL Oct 28 '13 at 10:20
  • i tested with row_id="3" and row_id="not 0|3" and all works. But if you do row_id="4", and only have 3 rows, it will show row 1. (adding to bug report) – GDmac Oct 28 '13 at 10:51
  • I've editted the post, row_id is database related, not row number related. – GDmac Oct 28 '13 at 11:14
  • Thanks for that. I think in that case that the database table ID should be easier to find -- it's pretty elusive as things stand. – RickL Oct 28 '13 at 11:48
  • you can use {if gridfield:count == 2 || gridfield:count == 3} or check if greater than {if gridfield:count > 2} – GDmac Oct 28 '13 at 12:00

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.