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.

Themes & Styling

Best practice for a long onepage site

Solved by Luap View solution

Started by Luap 6 years ago · 2 replies · 694 views
6 years ago

Heyho,

tldr: How can I call the entire content of all pages with page collections?

I'm new to grav and my php skills are quite limited. However I have already built a couple of websites with another flat file cms and wanted to try out grav and I like it so far.

I'm trying to build a onepager portfolio site with a straightforward content structure. There will be 10-15 projects each with 5 custom fields and some images. However there is a lot of content and so I thought, the modular page approach is not the right one. Please correct me, if I am wrong here.

I wanted to build a page for each project, and then call all project-pages on one page with Page Collections.

PHP
{% for p in page.collection %}
    {{ p.content }}
{% endfor %}

only outputs the content of the homepage, {{ p.title }} works though.

This is how I use Page Collections in the frontmatter of the homepage.

MARKDOWN
content:
    items: '@self.siblings'

How can I call the entire content of all pages with page collections? Or is it the wrong approach to build pages first?

Kind Regards,
luap

6 years ago

@luap, Without knowing your folder structure, the above snippets looks OK at first sight.

At first I thought it might be an issue of 'sibling' vs. 'descendants', but that doesn't match your remark that {{ p.title }} works and {{ p.content }} does not...

To be sure, I tried your code as follows:

  • Using a fresh installation of Grav 1.6.22, using theme Quark
  • Which has the following folder structure:
    TXT
    pages
    ├── 01.home
    │   └── default.md
    └── 02.typography
      └── default.md
    
  • Replaced the content of template 'themes/quark/templates/default.html.twig' with

    TWIG
    {% extends 'partials/base.html.twig' %}
    
    {% block content %}
      {# Your code snippet #}
      {% for p in page.collection %}
          {{ p.content }}
      {% endfor %}
    {% endblock %}
    
  • Added the following to the header of page '01.home/default.md:
    YAML
    content:
      items: '@self.siblings'
    

The 'Home' page now shows the content of page 'Typography', which is the one and only sibling of page 'Home'.

So, your snippets works as expected in above scenario...

By the way, the title of your post doesn't seem to fit your 'tldr', nor the entire content...

last edited 03/09/20 by pamtbaau
6 years ago Solution

Thanks for the answer! It was a misunderstanding on my side.
I was hoping content was calling the entire content of an page, like defined in my project.twig, but that didnt work.
So I have to call each custom field like I did in the project.twig file, but that's okay!

Looks like this now and works

PHP
{% block content %}

    {% for p in page.collection %}
        <h3>{{ p.title }}</h3>

        {%- if p.header.entext %}
            {{- p.header.entext|markdown -}}
        {% endif -%}

        {%- if p.header.detext %}
            {{- p.header.detext|markdown -}}
        {% endif -%}

        {%- if p.header.credits %}
            {{- p.header.credits|markdown -}}
        {% endif -%}
    {% endfor %}

{% endblock %}

Thanks!

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 222 2 months ago
Themes & Styling · by Ian, 2 months ago
3 118 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 481 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 72 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 132 3 months ago