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

B19: Previous entry's data gets passed to next entry if fields are left blank #514

Closed
aryehraber opened this Issue Mar 7, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@aryehraber

aryehraber commented Mar 7, 2016

Steps to reproduce

  1. Create a collection with multiple fieldtypes.
  2. Create a few entries for collection.
  3. Fill some entries in completely, leave some with blank fields (which means they won't appear in the entry's .yaml file) -- this is the key problem.
  4. Loop over collection in template using the specific field names (so don't use the json modifier).

Expected behaviour

All entries that don't have the specified fields simply show blank.

Actual behaviour

The data from the previous entry gets output.

Example

Fieldset:

title:
  type: title
  display: Title
is_in_stock:
  type: toggle
  display: In Stock?
quantity:
  type: text
  display: Quantity Available
price:
  type: text
  display: Price

Entry 1:

title: Product 1
is_in_stock: true
quantity: 4
price: 100

Entry 2:

title: Product 2

Template:

<h1>{{ title }}</h1>
<p>Is it in stock? {{ is_in_stock }}</p>
<p>Quantity: {{ quantity }}</p> 
<p>Price: {{ price }}</p>
@aryehraber

This comment has been minimized.

aryehraber commented Mar 7, 2016

I'm going to temporarily solve this by placing an empty default on each fieldtype.

Update

Scratch that... defaults with false or "" don't get saved to the entry's .yaml file. Filed under #515.

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Mar 7, 2016

You can use the scope parameter to make sure you are targeting the correct entry.

http://docs.talonsbeard.com/docs/tags/collection#scope

http://docs.talonsbeard.com/docs/recipes/cascade

{{ collection:products as="products" }}
  {{ products scope="product" }}
    {{ product:title }}
    {{ if product:in_stock }}{{ /if }}
  {{ /products }}
{{ /collection:products }}
@aryehraber

This comment has been minimized.

aryehraber commented Mar 7, 2016

@jasonvarga Ok that did the trick! Thanks so much!

Just wondering though, was I experiencing a bug? Or is this expected behaviour? Surely looping over a collection shouldn't output another entry's data?

@aryehraber aryehraber closed this Mar 7, 2016

@aryehraber

This comment has been minimized.

aryehraber commented Mar 7, 2016

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Sep 6, 2016

This was indeed a bug. It's fixed for 2.1.7.

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