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.

General

Page collection without frontmatter

Started by Robert August 7 years ago · 4 replies · 1109 views
7 years ago

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 :)

Thanks

7 years ago

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:

YAML
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.

7 years ago

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.

7 years ago

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](/t/new-pages-with-default-frontmatter/5585).

7 years ago

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!

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 101 17 hours ago
General · by pamtbaau, 22 hours ago
1 68 21 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 361 5 days ago
General · by Duc , 6 days ago
3 49 6 days ago