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

Username exists in frontmatter, need to see username when page is displayed

Started by Pamela Rathmell 8 years ago · 2 replies · 483 views
8 years ago

I have a basic grav installation on my localhost using the antimatter theme and the add page by form plugin. It seems to function properly.

Examining the submitted page shows the username has been captred in the front matter. I want to have the user name shown when the page is displayed.

I have done a lot of searching and experimenting, but I am still confused about how to get "username" into the actual post. I'm new to Grav, so I'm struggling with the level of abstraction and the depth of Grav. apologies if my question is ridiculously obvious.

8 years ago

Any variable which is present in a page's frontmatter can be displayed using Twig in a template. To test this you can extend the template default.html.twig to:

TWIG
{% extends 'partials/base.html.twig' %}

{% block content %}

        This user's name: {{ page.header.username }}

    {{ page.content }}
{% endblock %}

If you must you can use Twig in your page markdown content by setting

YAML
  process:
    markdown: true
    twig: true

in the pages section of the system.yaml configuration file. It's disabled (twig: false) by default.

I've been playing around with Grav for some time now and I find nothing obvious about it's workings. That I consider a good thing; kind of the downside of virtually unlimited flexibility.

👍 1
8 years ago

Thank you so much. I see it really is trivial but it was kind of you help.

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 54 11 hours ago
Support · by Anna, 3 days ago
2 60 14 hours ago
Support · by Justin Young, 15 hours ago
1 30 15 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 57 5 days ago