Help with Content

Hi. I’m obviously missing / misunderstanding something, so if anyone would care to help point me in the right direction I’d appreciate it.

I have a file user/pages/news/newsblog.md

The content is shown below. I’m trying to get return a collection of all of the children (news posts) but I want to traverse them in descending date order, that is the newest ones first.

Any help would be appreciated.

Randy

title: News Archive
content:
    items: '@self.children'
		order: date
		dir: desc
---

You’re on the right track, you just need to have a twig template that takes the resulting collection you have created with these settings and iterate over it.

The best way to do this is to check out a skeleton. I suggest the blog skeleton package. This page defines the blog listing:

And then this is rendered by the blog.html.twig template in the Antimatter theme.

This line creates a variable called collection from page.collection (just a shortcut really):

Then this is looped over and a partial used to render:

rhukster thanks for the quick response!

I checked your blog.md example and I tried the same thing. So I must be close. The only problem is that I get this error message. I’m wondering if this is perhaps a bug?

I used this:

title: News Archive
content:
    items: @self.children	
		order: 
			by: date
			dir: desc

and it returns this error message:
A YAML file cannot contain tabs as indentation at line 4 (near " order: ").

title: News Archive
content:
    items: @self.children
        order: 
            by: date
            dir: desc 
---

I did some further monkeying about on this and found the solution.

The correct YAML is as rhukster indicated:

title: News Archive
content:
  items: @self.children
  order:
    by: date
    dir: desc

The thing you need to be careful about is that the YAML is very sensitive and should be formatted with spaces only. Tabs may not work. In my case I took out the tabs and replaced them with spaces and we were all good to go from that point.