Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
Created December 2, 2014 22:38
Show Gist options
  • Select an option

  • Save cacheleocode/0fe44bc0afb88b038411 to your computer and use it in GitHub Desktop.

Select an option

Save cacheleocode/0fe44bc0afb88b038411 to your computer and use it in GitHub Desktop.
Django template that shows one author as simple HTML or multiple authors as tiles
{% if authors %}
{% if authors|length == 1 %}
{% for author in authors %}
<div class="article-author">
<h5>{% blocktrans %}Author{% endblocktrans %}</h5>
<h4><a href="{{ author.get_absolute_url }}">{% ifequal LANG 'ja' %}{{ author.display_name_ja }}{% else %}{{ author.display_name_en }}{% endifequal %}</a></h4>
<a href="{{ author.get_absolute_url }}"><img src="{% thumbnail author.image 120x180 upscale autocrop crop=",0" %}" alt="" class="thumbnail" /></a>
{{ author.bio|safe|linebreaks }}
</div>
{% if authors_articles|length > 1 %}
<h2>{% blocktrans with author.display_name as name %}Articles by {{ name }}{% endblocktrans %}</h2>
<div class="wall">
{% for author_temp, article_temp in authors_articles.items %}
{% if author_temp == author %}
{% for article in article_temp|slice:":1" %}
<div class="featured">
<div class="story">
<a href="{{ article.get_absolute_url }}">
<div class="image">
{% thumbnail article.signature_image2 300x210 upscale autocrop crop="smart" as thumb %}
{% if thumb.source_height > thumb.source_width %}
<img src="{% thumbnail article.signature_image2 300x210 upscale crop=",0" %}" alt="" />
{% else %}
<img src="{{ thumb }}" alt="" />
{% endif %}
<div class="overlay"></div>
</div>
<div class="info">
<div class="title"><h3>{{ article.title|safe|truncatewords:10 }}</h3></div>
</div>
</a>
</div>
</div>
{% endfor %}
<div class="first set">
{% for article in article_temp|slice:"1:10" %}
{%if forloop.counter|divisibleby:2 %}
{% else %}
<div class="story">
<a href="{{ article.get_absolute_url }}">
<div class="image">
{% thumbnail article.signature_image2 148x100 upscale autocrop crop="smart" as thumb %}
{% if thumb.source_height > thumb.source_width %}
<img src="{% thumbnail article.signature_image2 148x200 upscale crop=",0" %}" alt="" />
{% else %}
<img src="{{ thumb }}" alt="" />
{% endif %}
<div class="overlay"></div>
</div>
<div class="info">
<div class="title"><h3>{{ article.title|safe|truncatewords:10 }}</h3></div>
</div>
</a>
</div>
{% endif %}
{% endfor %}
</div> <!-- /set -->
<div class="last set">
{% for article in article_temp|slice:"1:10" %}
{%if forloop.counter|divisibleby:2 %}
<div class="story">
<a href="{{ article.get_absolute_url }}">
<div class="image">
{% thumbnail article.signature_image2 148x100 upscale autocrop crop="smart" as thumb %}
{% if thumb.source_height > thumb.source_width %}
<img src="{% thumbnail article.signature_image2 148x200 upscale crop=",0" %}" alt="" />
{% else %}
<img src="{{ thumb }}" alt="" />
{% endif %}
<div class="overlay"></div>
</div>
<div class="info">
<div class="title"><h3>{{ article.title|safe|truncatewords:10 }}</h3></div>
</div>
</a>
</div>
{% endif %}
{% endfor %}
</div> <!-- /set -->
<p class="more"><a href="{{ author.get_absolute_url }}">{% trans "More" %}</a></p>
{% endif %}
{% endfor %}
</div> <!-- /wall -->
{% endif %}{# authors_articles check #}
{% endfor %}
{% else %}
<div class="wall">
<h2>{% blocktrans %}Authors{% endblocktrans %}</h2>
<div class="first set">
{% for author in authors %}
{%if forloop.counter|divisibleby:2 %}
{% else %}
<div class="story">
<a href="{{ author.get_absolute_url }}">
<div class="image">
{% thumbnail author.image 148x157 upscale autocrop crop=",0" as thumb %}
{% if thumb.source_height >= thumb.source_width %}
<img src="{{ thumb }}" alt="" />
{% else %}
{% if author.random_number == 1 %}
<img src="{% thumbnail author.image 148x111 upscale autocrop crop="smart" %}" alt="" />
{% else %}
<img src="{{ thumb }}" alt="" />
{% endif %}
{% endif %}
<div class="overlay"></div>
</div>
<div class="info">
<h3>{% ifequal LANG 'ja' %}{{ author.display_name_ja }}{% else %}{{ author.display_name_en }}{% endifequal %}</h3>
</div>
</a>
</div>
{% endif %}
{% endfor %}
</div>
<div class="last set">
{% for author in authors %}
{%if forloop.counter|divisibleby:2 %}
<div class="story">
<a href="{{ author.get_absolute_url }}">
<div class="image">
{% thumbnail author.image 148x157 upscale autocrop crop=",0" as thumb %}
{% if thumb.source_height >= thumb.source_width %}
<img src="{{ thumb }}" alt="" />
{% else %}
{% if author.random_number == 1 %}
<img src="{% thumbnail author.image 148x111 upscale autocrop crop="smart" %}" alt="" />
{% else %}
<img src="{{ thumb }}" alt="" />
{% endif %}
{% endif %}
<div class="overlay"></div>
</div>
<div class="info">
<h3>{% ifequal LANG 'ja' %}{{ author.display_name_ja }}{% else %}{{ author.display_name_en }}{% endifequal %}</h3>
</div>
</a>
</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment