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.

Archive

Hiding parts of pages

Started by Muut Archive 10 years ago · 5 replies · 901 views
10 years ago

Can I hide or protect parts of page (or a modular page) that is accessible for everyone?

TWIG

Content open for every visitor to read {% if logged_in %}except for this classified string of text here {% end_if %} and we are back to the open stuff again.
---
10 years ago

In Twig that would work if logged_inwas set to true (and the statement was closed by endif). Are you thinking of protecting content in the Markdown, or in Twig?

10 years ago

You can restrict portions of you templates or even your page content (with process: twig: true in the page header with:

TWIG
{% if grav.user.authorize('site.secret') %}

[color=red]This is strictly controlled with `access: site.secret`[/color]

{% endif %}

This will allow any user with access: site: secret: true to access it:

YAML

access:
  admin:
    login: 'true'
    super: 'true'
  site:
    login: 'true'
    secret: 'true'
---
10 years ago

Thanks! That solved my problem perfectly.
Not that I need it right now but Gingah made me curious on the markdown approach. How would that be done?

10 years ago

I imagine the solution rhukster specified above could be used as a shortcode by extending the shortcode-plugin, so you could for example do:

TXT

[private=super]This content is only visible to admins with super: true.[/private]
---
10 years ago

Could be! if you want to add that shortcode, I would accept it as a PR for shortcode-core. Great way to learn too!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1281 9 years ago
Archive · by Muut Archive, 9 years ago
2 888 9 years ago
Archive · by Muut Archive, 9 years ago
2 4018 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1077 9 years ago