Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiding pages in branded grav site #1494

Closed
andy-miracl opened this issue May 25, 2017 · 6 comments
Closed

Hiding pages in branded grav site #1494

andy-miracl opened this issue May 25, 2017 · 6 comments
Labels

Comments

@andy-miracl
Copy link

Hi,

We have a site which we brand using site variables in different site.yaml files. However, certain brands should not publish certain pages.

I have tried to set the published flag in the page frontmatter dynamically using twig but it seems that this is not supported? Can I do this?

Can I do anything with page collections or taxonomies?

What other options are there for doing this?

Thanks for your help

Andy

@rhukster
Copy link
Member

so you have different site yaml files in different environment setups? like:

site-a.com/config/site.yaml
site-b.com/config/site.yaml

And you can't access these?

I'm not fully understanding what you are trying to do or trying to do it.

@andy-miracl
Copy link
Author

Hi, not quite. We have one grav source tree, but we have multiple site.yaml files for each brand.

e.g.
mysite/user/config/brand1.site.yaml
mysite/user/config/brand2.site.yaml

Before running a branded site we simply copy one of those to :

mysite/user/config/site.yaml

Lets say we have two pages in the site :

mysite/user/1.pagea
mysite/user/2.pageb
mysite/user/3.pagec

Lets say in brand1 I want all pages but in brand2 I want only pagea and pageb.

One simple solution is to delete or rename mysite/user/3.pagec before spinning up the site, but ideally Id like a neater solution. There are the 'published' and 'visible' attributes in the frontmatter for the page, but these dont seem to accept twig e.g. the following doesnt work


published : {{ site.brand_name != "brand2" }}

Is there some way of dynamically hiding a page? Or perhaps is there some way of declaring hidden pages in brand2.site.yaml? Alternatively, can I do something in the blueprint?

Thanks

Andy

@rhukster
Copy link
Member

You can use twig in frontmatter if you enable it in system.yaml:
pages.frontmatter.process_twig: true - https://learn.getgrav.org/basics/grav-configuration#pages

@andy-miracl
Copy link
Author

andy-miracl commented May 26, 2017

(Note we are running grav 1.2.4)

Thanks, Ive been trying this many different ways but cannot get it to work. Ive set the value in system.yaml and created a page :

---
title: My Page
published: {{ site.showpage  }}
---
published: {{ site.showpage  }}
system.pages.frontmatter.process_twig: {{ system.pages.frontmatter.process_twig }}

I get the following error :

Unexpected characters near "}" at line 2 (near "published: 1").

---
title: My Page
published: 1
---
published: 1
system.pages.frontmatter.process_twig: 1

If I remove the space padding inside the {{ }} e.g. :

---
title: My Page
published: {{site.showpage}}
---
published: {{site.showpage}}
system.pages.frontmatter.process_twig: {{system.pages.frontmatter.process_twig}}

I get this error :

Error: Invalid Frontmatter

Path: /home/andy/Documents/projects/maas_docs/user/pages/00.distributorguide/050.view-client-billing-information/docs.md

Malformed inline YAML string: 1 at line 2 (near "published: 1").

---
title: My Page
published: 1
---
published: 1
system.pages.frontmatter.process_twig: 1

If I try to return the string "true" or "false" instead e.g. :

---
title: My Page
published: {{site.showpage ? "true" : "false"}}
---
published: {{site.showpage ? "true" : "false"}}
system.pages.frontmatter.process_twig: {{system.pages.frontmatter.process_twig}}

I get :

Error: Invalid Frontmatter

Path: /home/andy/Documents/projects/maas_docs/user/pages/00.distributorguide/050.view-client-billing-information/docs.md

Unexpected characters near "}" at line 2 (near "published: true").

---
title: My Page
published: true
---
published: true
system.pages.frontmatter.process_twig: 1

@flaviocopes
Copy link
Contributor

Wrap the frontmatter twig in a string: published: "{{ site.showpage }}"

@andy-miracl
Copy link
Author

Great, thank you for clarifying that... :o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants