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

Blueprints for specific template children item

first-time form

Started by Ayoze 8 years ago · 2 replies · 1213 views
8 years ago

Hi all! Its my first topic here so be cheerful please 😛

Maybe its not possible what I require and also its not very hard to look for an alternative, but anyway I think it would be a smart solution (at least for me). What I want is add blueprints fields to only descendant pages from a specific template.

Ok, for example a /portfolio template contains many items.md, how could blueprints affect only to these kind of "items"?

As i said, another solution is just make another template for portfolio_item... But i would like to know all options ;)

8 years ago

Your best bet would be to indeed change the template on every subpage.
However, I think it is possible, and the only solution I can see, but it is quite advanced and kind of a hack, is to use the conditional field.

  1. Create a default.yaml blueprint in your theme blueprints/ folder that extend the existing default.yaml
  2. Use the conditional field to conditionnally display the fields

    YAML
                header.article_condition:
                  type: conditional
                  condition: "page.parent.header.apply_to_childpage ? 'true' : 'false'"
    
  3. Open your parent page in expert mode and add: apply_to_childpage: true

Now, your specific fields should only appear on these child pages.
If you need example, I use a lot of these conditional fields on my seo plugin, example:
https://github.com/paulmassen/grav-plugin-seo/blob/master/blueprints/seo.yaml#L110

Hope it helps!

👍 1
8 years ago

Its really helpfull! Thanks

but too much hacking for tonight I think haha. Maybe its clearer to have 2 kinds of items instead condition directly from blueprints. Anyway that solution helps to me for modular blueprints! Do you know if I could add a field to any modular template from blueprints/modular/default.yaml?

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 198 2 months ago
Themes & Styling · by Ian, 2 months ago
3 94 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 455 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 48 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 128 3 months ago