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.

Support

Make Certain Fields Visible to Only Logged in Users

Solved by Paul Hibbitts View solution

Started by Brian Callies 9 years ago · 4 replies · 933 views
9 years ago

I was wondering if it was possible to make parts of a page, certain fields, visible only to users that are logged in.

For instance, take a look at this linked page. I would like the fields under Statblock to be visible to me (or an Admin).

I just had a thought: I wonder if I could put those Statblock fields in a Partials template and somehow only include that partial if
an admin was logged in. I have no clue how to do that, if it's possible, or if there is a better way.

Any ideas?

Thank you,
Brian

9 years ago Solution

Hi @tmilktoast, perhaps this post might help?
/forum/archive/display-in-menu-only-if-logged-in-t7073

9 years ago

That looks promising. I'll try it out shortly. Thanks!

👍 1
9 years ago

Wonderful! That worked perfectly. I have to say, and I'm only a dabbler working on a personal project, but Grav is the most fun I've ever had making a web site.

Here's my code:

TWIG
{% if config.plugins.login.enabled and grav.user.username == "admin's user name" %}
    <h2>Statblock</h2>
    <div>
        {{ header.character.statblock|markdown }}
    </div>
{% endif %}
9 years ago

Awesome, so glad you got it working. Grav is brilliantly designed, and the use of Twig opens up customization possibilities for a lot more people (including myself, I am not a 'dev')🙂

👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 57 14 hours ago
Support · by Anna, 3 days ago
2 65 17 hours ago
Support · by Justin Young, 18 hours ago
1 33 18 hours ago
Support · by Duc , 1 week ago
2 68 5 days ago
Support · by Colin Hume, 1 week ago
2 60 6 days ago