Created
August 11, 2013 06:46
-
-
Save narration-sd/6203750 to your computer and use it in GitHub Desktop.
Achieving a list of authors in CraftCMS/Twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output: | |
Blog Entries with Authors | |
First Article | |
by F. Scott Fitzgerald - Ancestral, and James Michener - Dell Pocket Books | |
Second Article | |
by John Fowles - Oxford University, 이오령 - 이회여자대학교, and 김덕종 - KAIST Materials Science | |
Third Article and Counting | |
by Walter Fontana - Harvard Medical School | |
Code: | |
{% macro affiliate (author) %} | |
{%- if author.affiliation -%} | |
{{- " - " ~ author.affiliation -}} | |
{%- endif -%} | |
{% endmacro %} | |
{% import _self as macros %} | |
<h2>Blog Entries with Authors</h2> | |
{%- for article in craft.entries.section('blog').order('postDate asc').find() -%} | |
{{- "\n" -}}{{ article.title -}}{{- "\n<p>by " -}} | |
{% for author in article.authors %} | |
{%- if loop.length == 1 -%} | |
{{- author.anAuthor -}} | |
{{- macros.affiliate(author) -}}{{- "</p>" -}} | |
{%- elseif loop.length > 1 and loop.last -%} | |
{{- "and " ~ author.anAuthor -}} | |
{{ macros.affiliate(author) }}{{- "</p>" -}} | |
{%- else -%} {# within list #} | |
{{- author.anAuthor -}} | |
{{- macros.affiliate(author) -}}{{- ", " -}} | |
{%- endif -%} | |
{% endfor %} | |
{%- if not loop.last -%} | |
{{- "<br />" -}} | |
{%- endif -%} | |
{% endfor %} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment