Creating Collections and Listing Pages

Greetings,

I’m a novice and a dabbler when it comes to web development, so please bear with me. I’m working on a personal project that will, among other things, contain a database of characters in a game I’m running.

I have a character.yaml blueprint and its corresponding character.html.twig template which are both working fine (though the template style and layout is far from finished).

That’s great and I enjoyed figuring out how to do those, but at the moment I’m struggling a bit with Collections.

My goal is to have a page with a grid, or list, of all the characters which then can be clicked on to open a particular characters page.

From my understanding, I would create a blueprint called, for example, characters.yaml with something like:

title: Star Wars Characters

content:
  items: '@self.children'
  order:
    by: date
    dir: desc
  limit: 10
  pagination: true

Then I would create a Characters folder under which I would create each individual character?

Then I need to create a characters.html.twig template that would cycle through each character page and display a portrait, name, or whatever else?

If all of that is correct, then I’m doing something wrong, possibly at multiple levels. I think it may be my characters.html.twig file. Should the following work?:

{% embed 'partials/base.html.twig' %}

	{% set collection = page.collection() %}

	{% block content %}
           <div>
			{% for child in collection %}
			       {{ page.header.character.name }}
		        {% endfor %}
         </div>
	{% endblock %}

{% endembed %}

Maybe I should phrase my question better: Could someone explain, perhaps in simpler terms than the manual, how to create a collection of pages and display a list of those pages?

Thank you,
Brian

Okay, I see this is definitely wrong:

			{% for child in collection %}
			       {{ page.header.character.name }}
		        {% endfor %}

Should the following work:

			{% for p in page.collection %}
			       {{ p.header.character.name }}
		        {% endfor %}

It looks like I got it working. The listing page can now “access” the pages in the collection and display names and other data.

Besides the mistake in the twig file above, I also needed to manually edit the characters.md file with the collection information:

title: 'Characters List'
creator: brian
sitemap:
    changefreq: monthly
content:
    items: '@self.children'
    limit: 5
    order:
        by: date
        dir: desc
    pagination: true
    url_taxonomy_filters: true

I thought that stuff would be picked up from the blueprint, but maybe I did something wrong.

Thanks for letting me clutter up the forums while I worked this out.