Page collection without frontmatter

Hi,

for every new page that have collection inside or modules that have collection we have to setup the frontmatter like the following :

content:
items: ‘@self.children
order:
by: date
dir: desc
limit: 10
pagination: true

and the code inside the page would be like :
{% for collection = page.collection() %}
{%endfor%}

My question is :
can we embed the frontmatter inside the coding / inside twig like
for example :

{% for collection = page.collection(items: ‘@self.children’) %}
{%endfor%}

I’m not an expert with php, so I would need lots of help in this matter :slight_smile:

Thanks

Hi @hibangmike ! Welcome to the Grav Form.

You could save your collection definition in a separate YAML file and use the Grav Import Plugin to add it to a page header (also often called “frontmatter”).

I must admit that I haven’t tried it but in theory it should work.

BTW if you enclose code fragments by three backticks (`) the post will keep indentation so your code is much more readable like this:

content:
    items: ‘@self.children’
    order:
        by: date
        dir: desc
    limit: 10
    pagination: true

Let me/us know whether or not my suggestions works. If not, explain what you’ve done, what went wrong and we’ll try to help you further.

Hi bleutzinn, thank you for the welcome.

The reason I’m asking is because when I want to create new page / new category of pages dynamically. The site is a product showcase which have 3 level drop down navigation.

My problem is when the client / end users who want to create new categories by adding new page they have to go to expert mode and edit the frontmatter.

Because I am building a site for a client hoping that they could easily add product from the grav admin without editing the frontmatter and I could just embed that settings in my twig template.

Hope there is a solution for this. This is my first time using grav for a client by the way, I have used other CMS for previous project so I want to give grav a try.

So if I understand correctly the client can create a new category with a maximum of three levels deep navigation? So I assume they are allowed to create the category “root” page with child pages of that root page up to three levels. And therefor you need the collection in the category root page so all child pages can be handled in a Twig template.
Am I still assuming right?

If so you can have Grav include default frontmatter when a page is created as pointed out in this post [ New pages with default frontmatter](New pages with default frontmatter).

So if I understand correctly the client can create a new category with a maximum of three levels deep navigation?

Yes Correct, they can dynamically add folder / page and product categories up to three level, no problem in doing that but to setup each frontmatter when they create new page that will have pages inside it would be a hassle I think for the client.

If so you can have Grav include default frontmatter when a page is created as pointed out in this post [ New pages with default frontmatter](New pages with default frontmatter).

Yes, that is the solution I needed :), I didn’t know we can also manipulate the “add page” entry with predefined frontmatter in the admin blueprint yaml file.

Thank so much bleutzinn for the solution, works great!