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

Looped tag "merges" entries when referencing assets within #889

Closed
wojtiku opened this Issue Aug 25, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@wojtiku

wojtiku commented Aug 25, 2016

Steps to reproduce

  1. You have a file with the following yaml
contacts:
  -
    avatar: d7ba72ab-ff53-4bda-8661-ecf06f3f439d
    heading: General contact
    mail: mail@example.com
    phones:
      -
        number: +12 345 678 901
      -
        number: +12 345 678 902
    address: |
      Street name
      12345 City
      Country
  -
    avatar: 78bdfb60-2f5c-4ded-83a1-042f63049fcc
    heading: Product support
    mail: support@example.com
    other: |
      Support on duty
      Monday to Friday
      from 8 AM till 4 PM CET

and a template printing it

{{ contacts }}
            <dl>
                <dt>{{ heading }}</dt>
                <dd>
                    {{ asset:avatar }}
                        <img src="{{ url }}" alt="{{ heading }}"/>
                    {{ /asset:avatar }}
                </dd>
                {{ if mail }}
                <dt>E-mail</dt>
                <dd><a href="mailto:{{ mail }}">{{ mail }}</a></dd>
                {{ /if }}
                {{ if phones }}
                <dt>Phone</dt>
                <dd>
                    {{ phones | join }}
                </dd>
                {{ /if }}
                {{ if address }}
                <dt>Address</dt>
                <dd>
                    {{ address | nl2br }}
                </dd>
                {{ /if }}
                {{ if other }}
                <dd>
                    {{ other | nl2br }}
                </dd>
                {{ /if }}
            </dl>
    {{ /contacts }}
  1. Visit the page and the bug occurs - product support contact has phone and address visible even though it shouldn't. I also tried the glide tag and the same bug occurs so this is no the problem with asset tag directly but with referencing assets in general
  2. Remove the asset tag from the template
  3. Visit the page and the bug is not present anymore

Expected behaviour

Each loop execution should have only own fields

Actual behaviour

Each loop execution merges stuff in from the previous ones

Server configuration

Operating system:
OSX
Web server:
Mamp
PHP version:
7
Statamic version:
2.1.3, this started happening after the upgrade I think
Updated from an older Statamic or fresh install:
Updated but I also checked on a clean install
List of installed addons:
none

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Aug 25, 2016

{{ contacts scope="contact" }}
  {{ contact:phone }} etc
{{ /contacts }}
@wojtiku

This comment has been minimized.

wojtiku commented Aug 25, 2016

Thanks for helping with this on slack! It resolves my problem!

I still find it unintuitive though. Why would previous iteration influence the next one? I would understand if the page itself had a global field address for example and that would get used - perfectly clear case here. But borrowing data from previous iteration seems weird - especially that as I demonstrated it only happens when using assets.

@andypillip

This comment has been minimized.

andypillip commented Sep 5, 2016

This is terrible!

One needs to check the templates thoroughly for this case, otherwise contents end up in the wrong places, breaking the site from a content point of view.

Additionally it's not possible to scope inside scopes, e.g.

{{ contacts scope="contact" }}
  {{ contact:phones scope="phone" }}
  {{ phone:number }}
  {{ /contact:phones }}
{{ /contacts }}

would not work, which is totally necessary if you don't want to prefix all your fieldnames with the fieldset.

This makes it impossible to fix in cases where you need to iterate a second time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment