Make Certain Fields Visible to Only Logged in Users

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,

Hi @tmilktoast, perhaps this post might help?

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

1 Like

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:

{% if config.plugins.login.enabled and grav.user.username == "admin's user name" %}
        {{ header.character.statblock|markdown }}
{% endif %}

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’):slightly_smiling_face:

1 Like