authors
is a pre-formatted list (a text string). To get the raw data where you can pick just the last name, you need to access it from the creators
array. In creators
, the first and last name are stored separately as keys in a creator
object, along with the creatorType
.
To simply get the last name of the first author, you can get it from {{creators[0].lastName}}
. However, since creators can also be stored with a single name (for example in the case of organizations), it’s best to check if the creators has a {{creator.name}}
or {{creator.lastName}}
.
Tip
You can right-click things in the Data explorer to copy their template path.
However, this won’t give you for-loops and conditionals, as needed to do something for every creator, for example, or to only access creators of the author type.
Creating a formatted citation in the APA 7th citation style
Rather than always accessing only the first author, you could use the following macro to construct a formatted citation in the APA style (or another style, if you adjust it):
{# This macro formats APA citations #}
{% macro citationFormatter() -%}
{%- if creators -%}
{%- set citation = creators[0].lastName %}
{%- if creators|length == 2 -%}
{% set citation = citation + " & " + creators[1].lastName %}
{%- endif -%}
{%- if creators|length > 2 -%}
{% set citation = citation + " et al." %}
{%- endif -%}
{%- endif -%}
{%- if date -%}
{% set citation = citation + ", " + date | format("YYYY") -%}
{%- endif -%}
{{citation}}
{%- endmacro %}
Which you then use as follows:
{# Assign the result of citationFormatter to a variable called citation #}
{% set citation = citationFormatter() %}
{# Output the citation as needed #}
{% for annotation in annotations -%}
[!note|{{annotation.color}}]+ {{citation}} {{annotation.pageLabel}}
{# The rest of your annotation formatting #}
{% endfor %}
Saving creators to the properties
Another useful example of how to access and format data from creators:
---
creators:
{% for creator in creators %}
{%- if creator.name -%}
- "[[{{creator.name}}]]"
{%- else -%}
- "[[{{creator.firstName}} {{creator.lastName}}]]"
{%- endif %}
{% endfor -%}
---
Or if you want to group creators by creator type, split the creatorType so it’s not in camel case, and make the property singular or plural as needed:
{%- set camelRegex = r/([a-z])([A-Z])/g %}
{%- for type, creators in creators | groupby("creatorType") %}
{% if creators.length > 1 %}{{type | replace(camelRegex, "$1 $2") | lower | trim}}s:{%- for creator in creators %}{% if creator.name %}
- {{creator.name}}{% else%}
- {{creator.firstName}} {{creator.lastName}} {% endif %}{%- endfor %} {% else -%}
{{type | replace(camelRegex, "$1-$2") | lower | trim}}:{%- for creator in creators %}{% if creator.name %} "{{creator.name}}"{% else%} "{{creator.firstName}} {{creator.lastName}}"{% endif -%}{%- endfor -%}{% endif -%}{% endfor %}
This latter example gives you something like:
---
author: John Doe
editors:
- Jane Doe
- Adam Smith
---