Add Author name in blog post?

Hello I have just tried GRAV and found it extremely powerful and easy to use.
I just want to add author name, picture and some info at the end of a page.

You can add those things in the page header frontmatter, then you will have them available to access via the twig. If it’s an author you use frequently, you could put that information in the site.yaml, so you dont have to repeat it per page:

/user/config/site.yaml

author:
  andym:
      name: Andy Miller
      email: andy@email.com
      avatar: /images/andym.jpg
      bio: some short biography here

Then in your twig you have modified to show the author you can access the bits like this:

<b>Author Name: {{ site.author.andym.name }}</b>

I pasted the author info in site.yaml but when I used Author Name: {{ site.author.andym.name }} nothing happened! The Urban Jungle _ Grav

Hi Ashok,

it looks like you have to prepend config. in front of site, since you are accessing a config variable from site.yaml (see http://learn.getgrav.org/themes/theme-vars#site-object ). Thus,

<b>Author Name: {{ config.site.author.andym.name }}</b>

will do the job.

Its bit confussing, but if I got you right I just have to paste the code in the “.md” file, Right? File Manager

There are two ways for you you should consider. First you can paste the above code directly in your “.md” file, but then you explicitely have to enable Twig in the page header via

process:
    twig: true

(see [Learn Grav -> Headers](http://learn.getgrav.org/content/headers#process for the documentation) ). However you have to repeat this (set twig in header + insert code in “.md” file) for every “.md file” you want to show the author. In this case the second option might be more interesting for you (however for testing purposes the first approach is perfect).

It runs as follows: you modify the Twig file of your template, i.e. if you have Antimatter installed you modify user/templates/partials/blog_item.html.twig somewhere around Line 31 and add

<b>Author Name: {{ config.site.author.andym.name }}</b>

to the code.

Since you are modi fying a template then you probably want to consider template inheritance, too, to keep your changes after updating your base theme(s).

hmmm. {{ site… }} should work fine also. It is a shortcut to config.site, but should still work, if it doesn’t can someone ticket that as an issue?

{{ site.author.andym.name }}

This works. I just tested it with newest grav so it’s not an issue.

Maybe you have other “author” values in site.yaml and they are overriding each other ? Author it’s often there by default.

Hi @rhukster, maybe you both are right. I don’t have a machine here to test*. I guess the OP is missing the page header process: twig: true in the “md” file, which will solve the problem. However, if {{ site.author.andym.name }} works, the documentation has to be updated, though.

  • I will test it, when I’m back at home and leave a message here, when this is not working.

Documentation appears to be fine: http://learn.getgrav.org/themes/theme-vars#adding-custom-variables

Ok, the documentation said it, it’s an alias. But it is a little confusing for me. An example would be fine.

Example is in my above link :slight_smile: It’s just not in site object :slight_smile:

I tried all but no luck, can someone provide me complete files in which edits are made, then it would be a lot more easier for me?

Oh wait a minute, I just tried the step mention by the ‘admin’ on GRAV defualt install and it worked like a chram, but its not working on skeleton pacakge ‘Blog Site’ in which I was previously trying. Can anyone confirm that this can be done in ‘Blog Site’ ?

This can be done in ‘Blog Site’. Where exactly are you pasting the code ? Maybe you can send me whole skeleton using dropbox or gitter ? or at least paste code from a file here ?

Here’s the blog post:

title: The Urban Jungle
date: 17:34 07/04/2014 
taxonomy:
    category: blog
    tag: [travel, photography, city]
    author: andym
    process: 
    twig: true

xyz			
{{ site.author.andym.name }}

and here’s site.yaml file:

title: Grav
author:
  name: Andy Miller
  email: 'andy@email.com'
blog:
  route: '' 
metadata:
    description: 'Grav is an easy to use, yet powerful, open source flat-file CMS'
taxonomies: [category,tag,month]

Your declaring those details inside of taxonomy which is incorrect.

Try something like below

title: The Urban Jungle
date: 17:34 07/04/2014
author: andym
process:
    twig: true
taxonomy:
    category: blog
    tag: [travel, photography, city]
---

Durlabh this makes no sense.
{{ site.author.andym.name }} should be placed INSIDE twig template. So if your page files is called item.md then corresponding twig template file should be: item.html.twig. Then for example after

<div class="blog-content-item grid pure-g-r">

you can paste your code: {{ site.author.andym.name }}
And author will show for all blog items. :slight_smile: