Search code examples
jekyllliquid

Jekyll - unable to get the url and the name of the author


I am trying to fetch author details to display near their blog with the following code

{% assign author = site.authors | where: 'name', post.author %}
{% if author %}
- <a href="{{ author.url }}">{{ author.name }}</a>
{% endif %}

while i try to print the author using {{ author }} it displays the author page in the view, but while i try to print anything like {{author.url}} or {{author.name}} it doesn't print anything.

Also while i separately print the author details with the following code it displays the details

{%- for aut in site.authors-%}
{{aut.name}}
{{aut.url}}
{%- endfor -%}

Any help would be appreciated.


Solution

  • {% assign author = site.authors | where: 'name', post.author %}
    

    This returns an array containing matching elements or nil if no matching element is found.

    If matching element is supposed to exist and be unique, you can get it by using the first array filter like this :

    {% assign author = site.authors | where: 'name', post.author | first %}