Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

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

Started by Pamela Rathmell 8 years ago · 2 replies · 596 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 Paul Hodges, 4 weeks ago
19 485 5 days ago
Support · by Lauw, 7 days ago
2 99 7 days ago
Support · by Anna, 3 weeks ago
4 426 1 week ago
Support · by gtx, 4 weeks ago
4 377 3 weeks ago
Support · by Anna, 1 month ago
9 484 3 weeks ago