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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Custom Collection for Footer?

Solved by amdival View solution

Started by amdival 5 years ago · 4 replies · 671 views
5 years ago

I'm struggling with trying to figure out how to create a custom navigation list for my footer. I want to have a folder with pages, and have my footer navigation be populated with links to those pages.

This is what I feel like should work:


config.themes.steadystation.yaml

YAML
footnav:
    items:
        '@page.children': '/footnav'
    order:
        by: default
        dir: desc

base.html.twig

TWIG
{% for p in config.themes.steadystation.footnav %}
{{ p.title }}

Pages Folder Structure

TXT
01.Home
02.Promo
03.Etc
footnav
  01.brands
  02.title
  03.info
  04.etc
images

The above doesn't work.

I've tried lots of other things and cannot seem to get it to work. Is this even the right approach? Should I be defining a collection in the theme yaml? Do I even need a collection? My main nav is just using pages.children.visible in the TWIG. I don't know how to edit that to only look in one folder. I've tried pages.footnav.children.visible, but that doesn't seem to work.

5 years ago Solution

I figured out how to do it with Taxonomies. I have not yet used taxonomies for anything yet, and this was an easy solution.

I edited config.site.yaml to have

taxonomies: [place]

Added the appropriate Taxonomy to each page:

YAML
 taxonomy:
     place: footer

Then used this in my TWIG:

{% for page in taxonomy.findTaxonomy({'place':'footer'}) %}

5 years ago

You can mark your own answer as a solution ;)

I also use category taxonomy for that exact purpose. And I'm not sure themes can have page collections 🤔 I always thought they can be created only in page header

👍 1
5 years ago

@Karmalakas, See Programmatic collections:

You can take full control of collections directly from PHP in Grav plugins, themes, or even from Twig. This is a more hard-coded approach compared to defining them in your page frontmatter, but it also allows for more complex and flexible collections logic.

5 years ago

Probably that's why I didn't fixate that to my memory :) I didn't really use the usual way of getting collections on my site - everything is in my custom theme templates as page.children and similar

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 51 8 hours ago
Support · by Anna, 2 days ago
2 58 10 hours ago
Support · by Justin Young, 11 hours ago
1 30 11 hours ago
Support · by Duc , 1 week ago
2 63 5 days ago
Support · by Colin Hume, 1 week ago
2 55 5 days ago