Created
August 12, 2013 06:17
-
-
Save narration-sd/6208607 to your computer and use it in GitHub Desktop.
A cleaner, more knowledge-applying example of building article author attribution lists in Twig/Craft CMS.
This file contains 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
<body> | |
{% spaceless %} | |
{% 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() %} | |
<h3>{{ article.title -}}</h3> | |
<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>\n" -}} | |
{%- else -%} {# within list #} | |
{{- author.anAuthor -}} | |
{{- macros.affiliate(author) -}}{{- ", " -}} | |
{%- endif -%} | |
{% endfor %} | |
{% endfor %} | |
{% endspaceless %} | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment