From 799b4e575733c16d2376a1d62d3f0312b1ef3060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt?= <b.charpentier@webu.coop> Date: Fri, 13 Jan 2017 13:45:33 +0100 Subject: [PATCH] refactoring list-item --- newsbox/templates/newsbox/inc/list-item.html | 12 ++++--- .../templates/newsbox_cms/inc/list-item.html | 33 +++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/newsbox/templates/newsbox/inc/list-item.html b/newsbox/templates/newsbox/inc/list-item.html index b9021ec..f11f102 100644 --- a/newsbox/templates/newsbox/inc/list-item.html +++ b/newsbox/templates/newsbox/inc/list-item.html @@ -16,11 +16,13 @@ <div> {% block newsbox_list_item_content %} <div class="summary"> - {% if object.newsbox_summary %} - {{ object.newsbox_summary|linebreaks }} - {% else %} - {{ object.newsbox_body|truncatewords:50 }} - {% endif %} + {% with summary_max_words=summary_max_words|default:50 summary=summary|default:object.newsbox_summary|default:object.newsbox_body %} + {% if summary_max_words and summary_max_words != '0' %} + {{ summary_max_words }}{{ summary|truncatewords_html:summary_max_words }} + {% else %} + {{ summary }} + {% endif %} + {% endwith %} </div> {% block newsbox_list_item_content_extra %} diff --git a/newsbox_cms/templates/newsbox_cms/inc/list-item.html b/newsbox_cms/templates/newsbox_cms/inc/list-item.html index bcfe705..a370a5b 100644 --- a/newsbox_cms/templates/newsbox_cms/inc/list-item.html +++ b/newsbox_cms/templates/newsbox_cms/inc/list-item.html @@ -6,23 +6,22 @@ {{ block.super }} {% endblock %} -{% block newsbox_list_item_content %} - <div class="summary"> - {% if object.newsbox_summary %} - {{ object.newsbox_summary }} - {% render_placeholder object.newsbox_body as body %} - {% else %} - {{ body|truncatewords_html:50 }} + +{% block newsbox_list_item_content_extra %} + {% render_placeholder object.newsbox_body as body %} + {% with readmore=body %} + {% if not instance.placeholder %} + {{ block.super }} + {% elif readmore %} + <div class="extra"><a class="readmore" href="{{ object.get_absolute_url }}">{% trans "Read more" %}</a></div> {% endif %} - </div> + {% endwith %} +{% endblock newsbox_list_item_content_extra %} - {% block newsbox_list_item_content_extra %} - {% with readmore=body %} - {% if not instance.placeholder %} - {{ block.super }} - {% elif readmore %} - <div class="extra"><a class="readmore" href="{{ object.get_absolute_url }}">{% trans "Read more" %}</a></div> - {% endif %} - {% endwith %} - {% endblock newsbox_list_item_content_extra %} +{% block newsbox_list_item_content %} + {% render_placeholder object.newsbox_body as body %} + {% with summary=object.newsbox_summary|default:body summary_max_words=instance.placeholder|yesno:'50,0'%} + {{ block.super }} + {% endwith %} {% endblock %} + -- GitLab