picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

Using custom modified date for sorting #583

Closed cronhill closed 3 years ago

cronhill commented 3 years ago

Hej guys,

I try to do a Last modified List with a custom meta data. The meta data is named: Changed.

The input value is in this format: 2021-05-06. I put the field in the meta section like this: Changed: 2021-05-06

I use the pages loop to get the pages:

`

`

And the value of changed is displayed correctly. But I can't sort after it.

I tried different values for sort_by like page.meta.changed, meta.changed or even changed, but nothing happens.

The list is nort sorted. I would appreciate help! I am a developing designer, not a designing developer. So I tried to find the best out of Pico Docs and Twig Docs, but it doesn't helped me, I worry.

Thanks for help and regards, Thomas

PhrozenByte commented 3 years ago

Until you register the YAML header using a plugin (onMetaHeaders event, see DummyPlugin) or your theme's pico-theme.yml (key meta, see example), you must use key Changed (note the uppercase C) to access this meta value. Also note that Pico's sort_by Twig filter expects [ 'meta', 'Changed' ] as parameter.

    <ul class="list--pages list-unstyled">
        {% for page in pages("", depth=3)|sort_by([ 'meta', 'Changed' ])|reverse if not page.hidden %}
            <li>{{ page.meta.Changed|date("Y/m/d") }}  <a href="{{ page.url }}">{{ page.title }}</a> </li>
        {% endfor %}    
    </ul>
cronhill commented 3 years ago

Thanks so much for this fast and nice support. This worked perfectly.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: