Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Make Certain Fields Visible to Only Logged in Users

Solved by Paul Hibbitts View solution

Started by Brian Callies 9 years ago · 4 replies · 1291 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 webmasterodp, 5 days ago
4 126 4 days ago
Support · by nwhitfield, 6 days ago
2 109 6 days ago
Support · by stell, 2 weeks ago
5 356 1 week ago
Support · by gravinator, 1 month ago
5 547 1 week ago
Support · by Gravver, 3 weeks ago
6 340 3 weeks ago