divio / aldryn-newsblog

A combined news/weblog application for Aldryn and django CMS – part of the Essential Addons.
https://marketplace.django-cms.org/en/addons/browse/aldryn-newsblog/
Other
67 stars 118 forks source link

Breadcrumbs #470

Open vxsx opened 7 years ago

vxsx commented 7 years ago

It's usually a problem creating breadcrumbs for newsblog, i believe it's something that should be included in the package.

Currently on (3.4.4) I'm using this snippet, which is a bit of a monstrosity:

{% block extend_breadcrumb %}
    <li class="child">
        <a href="{% url 'pages-root' %}">{% page_attribute "page_title" "home" %}</a>
    </li>
    {% for page in request.current_page.get_ancestors.all %}
        <li class="child">
            <a href="{% page_url page %}">{% page_attribute "page_title" page %}</a>
        </li>
    {% endfor %}
    {% if article or newsblog_author or newsblog_year or newsblog_month or newsblog_category or newsblog_tag %}
        <li class="child">
            <a href="{% page_url request.current_page %}">{% page_attribute "page_title" request.current_page %}</a>
        </li>
    {% else %}
        <li class="child active">
            {% page_attribute "page_title" request.current_page %}
        </li>
    {% endif %}
    {% if newsblog_author %}
        <li class="child active">
            {{ newsblog_author.name }}
        </li>
    {% endif %}
    {% if article %}
        <li class="child active">
            {{ article.title }}
        </li>
    {% endif %}
    {% if newsblog_year and not newsblog_month %}
        <li class="child active">
            {{ newsblog_year }}
        </li>
    {% endif %}
    {% if newsblog_year and newsblog_month %}
        <li class="child">
            <a href="{% namespace_url 'article-list-by-year' year=newsblog_year namespace=request.resolver_match.namespace default='' %}">{{ newsblog_year }}</a>
        </li>
    {% endif %}
    {% if newsblog_month and newsblog_archive_date %}
        <li class="child active">
            {{ newsblog_archive_date|date:"F" }}
        </li>
    {% endif %}
    {% if newsblog_tag %}
        <li class="child active">{% trans "Tag" %}: {{ newsblog_tag }}</li>
    {% endif %}
    {% if newsblog_category %}
        <li class="child active">{{ newsblog_category }}</li>
    {% endif %}
{% endblock %}

This would be much better as a template tag or directly integrated into show_breadcrumb cms template tag.