Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeater fields are omitted when viewing the "preview" link of a record #6605

Closed
eduardomart opened this issue May 1, 2017 · 12 comments
Closed

Comments

@eduardomart
Copy link
Contributor

This one is pretty straight forward, when you have a repeater in your content type and try to use the preview link for a record on the backend, you're taken to the preview page but all fields that are part of the repeater are omitted.

Details

  • Relevant Bolt Version: [ 3.2.11 ]
  • Install type: [ Zip/tarball install | Composer install ]
  • PHP version: [ 7.0 ]
  • Used web server: [ Apache ]
  • For UX/UI issues: [ Safari 10. ]
@bobdenotter
Copy link
Member

This seems to be a tricky one to solve. Let's say we have this:

foobar:
    name: Foobars
    singular_name: Foobar
    fields:
        title:
            type: text
            class: large
        slug:
            type: slug
            uses: title
        teaser:
            type: html
            height: 150px
        foo:
            type: repeater
            fields:
                repeattitle:
                    type: text
                foobar:
                    type: html

And in the foobar.twig we use:

        {% for repeater in record.foo %}
             {{ dump(repeater)}}
        {% endfor %}

When "previewing" a record with this, the repeater fields are passed in to the template as plain arrays:

screen shot 2017-05-01 at 22 12 33

When viewing the actual saved page, the repeaters work as expected:

screen shot 2017-05-01 at 22 12 48

I don't know if it's feasible to fix this.

@eduardomart
Copy link
Contributor Author

This will probably affect the upcoming Named Repeaters as well.

@rossriley
Copy link
Contributor

rossriley commented May 2, 2017

I can't see how this causes an issue, yes the objects/arrays are different but if in the template you use:

{% for repeater in record.foo %}
    {{ repeater.repeattitle }}
    {{ repeater.foobar }}
{% endfor %}

then as far as I can see the same code will work wether the repeater is a raw array or one of the lazy objects which is only a pointer to the same data structure underneath.

@bobdenotter
Copy link
Member

bobdenotter commented May 2, 2017

In that case they will "just" not work when you're previewing a record which template uses the {{ fields() }}-tag. That is something I can handle in that template, which should be good enough until the full switchover to Storage Layer.

So:

  • Template without fields() + frontend request = ✅
  • Template without fields() + "preview" request = ✅
  • Template with fields() + frontend request = ✅
  • Template with fields() + "preview" request = ⛔️ (but with a nice message)

We can live with that.

@SahAssar
Copy link
Contributor

SahAssar commented May 2, 2017

@rossriley It's working in that case because it isn't using the foo.get('bar') syntax, right? Becuase the get syntax is still the only one that works with repeaters in templatefields, right?

@rossriley
Copy link
Contributor

Yes, looks like that's the case. I'm guessing the best way to do this is to find a way to hydrate the content object correctly in the preview() controller method, but I'm not sure how easy that will be.

@bobdenotter
Copy link
Member

Also note: In Bolt 3.2x the repeaters are omitted. In Bolt 3.3 it throws an exception:

screen shot 2017-05-07 at 16 09 30

Workaround incoming.

@bobdenotter
Copy link
Member

Closed by #6633

@jadwigo
Copy link
Contributor

jadwigo commented Aug 7, 2017

This is still broken.
If an editor previews a new record the repeaters will not be usable in the template.
Calls to {{ repeaterfield.get('attribute') }} will fail because the repeater fields are arrays in the preview.

(Bolt 3.3.1)

@jadwigo jadwigo reopened this Aug 7, 2017
@GwendolenLynch GwendolenLynch changed the title [BUG] Repeater fields are omitted when viewing the "preview" link of a record Repeater fields are omitted when viewing the "preview" link of a record Sep 27, 2017
@zomars
Copy link
Contributor

zomars commented Oct 3, 2017

Just my two cents, this is my quick and dirty solution when rendering templates:

{% set is_preview = attribute(item, 'values') is not defined %}
{% set data = is_preview ? item.field_name : item.get('field_name') %}
{{ data }}

@bobdenotter
Copy link
Member

bobdenotter commented Oct 15, 2017

Calls to {{ repeaterfield.get('attribute') }} will fail because the repeater fields are arrays in the preview.

Yes, this is true, unfortunately. It's not something that's feasible to change in the short run, though..

I think {{ repeaterfield.attribute }} works both in preview and in "normal" page requests.

@bobdenotter
Copy link
Member

After giving it some more thought, let's just update the docs and make the 'dot notation' the recommended way.. That'll work in both "regular" as well as in "preview", and doesn't require cumbersome if-statements.

See here: bolt/docs#838

So, closing this one again. Hopefully for good, this time. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants