Show Author on pages

Hello,

I am looking to show author at the top of every page created. I found a few other references here but can not seem to get it to work.

Those references are:

I attempted to add both examples just above the messages block in base.html.twig.

For reference I am looking to show authors sort of like this:

I tried to use this plugin as well, doesn’t seem to work:

Any help is appreciated.

What theme are you using @dazik?

@paulhibbitts My apologies, that would have been useful information. Quark.

1 Like

Thanks @dazik, no problem🙂 Welcome to Grav!

Just as a proof-of-concept, if you locate the Quark theme file at user/themes/quark/templates/partials/blog/date.html.twig and view the file you should see this:

<span class="blog-date">
<time class="dt-published" datetime="{{ page.date|date("c") }}">
    <i class="fa fa-calendar"></i> {{ page.date|date(system.pages.dateformat.short) }}
</time>

To get at least get the field author of the current blog item to display change that file to include {{ page.header.author }}, so it looks like this:

<span class="blog-date">
{{ page.header.author }}
<time class="dt-published" datetime="{{ page.date|date("c") }}">
    <i class="fa fa-calendar"></i> {{ page.date|date(system.pages.dateformat.short) }}
</time>

Nothing fancy of course, but this should be a good start for you.

A more elegant approach would be to create a new author.html.twig template file in that same folder, and then include that as a partial here:

Just as a heads-up, direct edits to theme files can be overwritten during theme updates, so it is a good idea to first create a child or inherited theme (which is best for smaller changes) - more info at https://learn.getgrav.org/15/themes/customization#theme-inheritance

Let me know if the above works for you.
Paul

Hi @paulhibbitts,

Awesome, definitely puts me on the right path. However, I am looking to do it for default pages, not blog posts.

Cheers

1 Like

Oh, sure here is a starting point for that:

Locate the Quark theme file at user/themes/quark/templates/default.html.twig and view the file you should see this:

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

{% block content %}
    {{ page.content|raw }}
{% endblock %}

And change that file to look like this:

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

{% block content %}
    {% include 'partials/blog/author.html.twig' %}
    {{ page.content|raw }}
{% endblock %}

Again, nothing fancy but should help point you to the right spot etc. You would likely also want to move that author.html.twig file to just user/themes/quark/templates/partials/

BTW, I am not a dev myself but once you are learning some of the basics of the Grav architecture it is pretty amazing what you can do with a bit of HTML/CSS/Twig knowledge.

Good luck!

@paulhibbitts
Awesome, exactly the information I needed. Thanks!

I was a developer once upon a time (PHP). Getting used to this twig template system is weird to me. But, I’ll figure it out. Only 2 days in!

1 Like

:slightly_smiling_face: If you have not already seen this page it contains lots of helpful resources to get going https://github.com/getgrav/awesome-grav

I got it now, using the info you gave me was pretty much instant learning.
I created a new page type (Articles) based off default, using bits and pieces from blog.

All setup exactly how I wanted. Big thanks again. :slight_smile:

1 Like