Tom Maton
Tom Maton

Reputation: 1594

Assemble partial looping through data

I'm using Assemble to generate a new site and want to modularise as much as possible. One of the components will be looping through a list of data and generating a list of items.

My component is called ratings and looks like this:

---
ratings:
    - review: I would recommend this company.
      reviewRating: 10
      reviewLocation: Berkhamsted 
      reviewDate: 11/03/2014
    - review: Very pleasant, very prompt, fantastic, I would recommend them.
      reviewRating: 10
      reviewLocation: Cranbrook 
      reviewDate: 11/02/2014
    - review: Very reliable and very nice people to have around your property, great workmanship.
      reviewRating: 10
      reviewLocation: Chelmsford 
      reviewDate: 16/10/2013
    - review: Excellent service and I have recommended them to other people
      reviewRating: 10
      reviewLocation: Dartford 
      reviewDate: 14/06/2013
    - review: Very professional and great installation. I would have them back. Couldn't more pleased with them. Outstanding, top class.
      reviewRating: 10
      reviewLocation: Halstead
      reviewDate: 29/04/2013
---

{{#forEach ratings}}
    {{reviewRating}} - {{review}} -- {{reviewLocation}} --- {{reviewDate}}
{{/forEach}}

And in my page I have the following:

{{> ratings }}

When I then compile the Assemble files I get the following error

Warning: Cannot read property 'length' of undefined Use --force to continue.

But when I include the data and the loop in the page then it works fine but doesn't allow for re-use.

Upvotes: 1

Views: 309

Answers (1)

doowb
doowb

Reputation: 3372

Assemble v0.4.x namespaces partial front matter with the name of the partial, so you should be able to access it like...

{{#forEach ratings.ratings}}
    {{reviewRating}} - {{review}} -- {{reviewLocation}} --- {{reviewDate}}
{{/forEach}}

The first ratings is the name of the partial and the second `ratings is the list in your front matter.

Try that and see if it works.

Upvotes: 1

Related Questions