Documentation of Find - Help Building a Recipe

Good morning.

I am trying to build a twig template (a partial) that locates the last N updated pages under a particular route and lists them out: a “What’s New!” ability for a page. I assumed I could use the find() function to drive this iterative search.

However, I am having a little trouble finding the documentation I need. I am sure this is because I am coming to Grav and Twig very new and I am not sure where boundaries between things lie. I looked at the Twig doc site for information.

Clues would be appreciated.

Thanks.

To clarify:

  1. traverse all children beneath a specified route (e.g., /).
  2. collect all children in an array/collection
  3. sort the array by date
  4. take the top nth children and make a “what’s new” list on the page

My hang-up is I don’t know the syntax well-enough and can’t seem to find a primer or coherent doc, so I am staring a twig templates trying to suss out the how.

What you might want to do is look at the related-pages plugin. This basically does some logic and uses dynamically assigned taxonomy to associate related pages. This is one approach.

Another option is to use page.collection which is populated by collection page headers.

A third approach would be to use a taxonomy.findTaxonomy call to retrieve pages, then manipulate the resulting collection to order by date.

Really there are many ways to achieve this.

Thank you. How, exactly, do you make a page.collection on page headers? There is no specific example of this on the link you pointed at.

In general, all of these seem to rely on inserted data into the pages specifically to be found later. I want to avoid some of this (for example, not all of these pages require, or even need, taxonomy). I suppose I could generally try to build a collection from page.header.title, but I am not exactly clear on the syntax to do so:

content:
items: page.header.title

Is this something, implied by some of the language on that page, that you must set up in the site.yaml file beforehand?

Again, specifics documentation examples, or code examples, would greatly be appreciated.

Hi

Within your MD file you usually have the page title as the first thing at the top so something like

title: Your Page Title

Within your twig file you can do {{ page.header.title }} and it outputs that onto the page…

Thanks for the reply. Yes, I understand that. I was asking how I could use the collection mechanism to collect up all the files with a particular header.

Thanks!

Ah I see I have something similar on my site but not exactly what you want. Perhaps the below piece of code could be usefull for you? I basically needed to output all child folders onto a page and display an image, header text and link for it which the below does.

{% for p in page.find('/wallpapers').children if p != page %}
   {{ dump(pages.find('/images/landing-page-      thumbnails').media.images[p.header.artistimg~'.jpg']) }} {{p.header.artistimg}} <a href="{{p.url}}/">{{ p.title}}</a>
{% endfor %}
---