Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Multiple Authors and Blueprints

Started by Muut Archive 10 years ago · 1 replies · 498 views
10 years ago

I'm trying to setup a method to have multiple authors, an author page for each author, and be able to select a blog post's author using the antimatter theme. I have an authors page with a custom authors.html.twig that shows all authors. I did this by creating a collection for the authors page for all descendants and then creating a subpage in /mysite/authors for each author. In user/config/site.yaml I've created an entry for each author, like so:

YAML
author:
   joe:
      name: Joe Sample
      bio: Bio for Joe
   peter:
      name: Peter Sample
      bio: Bio for Peter

In system/blueprints/pages/default.yaml I added

YAML
header.author:
   type: textarea
   label: Author
   yaml: true  

So I can easily add an author to each blog post from the page creation screen. The problem I'm having is with my authors pages. I have a custom authors_item.html.twig file as the default format for all author pages. I need to iterate over all others in site.yaml and see if it matches page.header.author. I've tried

TWIG
{% for author in site.author if author == page.header.author %} 

Which does not work and shows nothing. If I leave out the "if author == page.header.author" section, the for loop does iterate, but it iterates 4 times even though I only have 2 author entries in site.yaml. I've also tried

TWIG
{% if page.header.author in site.author %}

Which doesn't work and probably shouldn't lol. Basically I'm trying to loop over all entries in the author section of site.yaml and compare it to the author in the header of a page. If I can loop over entires in the author section of site.yaml I could also take care of selecting an author for each page using the same. Does anyone know how to go about doing this? How do you iterate over something in site.yaml. Is there an alternative way to achieve what I'm trying to do? Am I making this way more complicated than it needs to be?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1370 9 years ago
Archive · by Muut Archive, 9 years ago
2 943 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1127 9 years ago