Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace tags with category for index blog cards #3637

Merged
merged 14 commits into from
Sep 17, 2019
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "./generic-card.html" %}

{% load wagtailcore_tags wagtailroutablepage_tags class_tags %}
{% load wagtailcore_tags wagtailroutablepage_tags class_tags blog_tags %}

{% block card_type %}blog-card{% endblock %}

Expand All @@ -22,16 +22,11 @@
{% endfor %}
</ul>
{% else %}
{# Show the tag's own "main" tag (i.e. first tag in its tag list) as each blog card's visible tag #}
{% with tag=page.specific.tags.first %}
{% if tag %}
{% if root %}
{# If we have a "root" context variable, we know this card is generated on an index page (or index page subroute) #}
<a class="main-tag d-block mt-3" href="{% routablepageurl root.specific "entries_by_tag" tag.slug %}">{{ tag }}</a>
{% else %}
{# If we do not have a "root" context variable, this card is being generated outside of an index page, and so needs to use its parent as root #}
<a class="main-tag d-block mt-3" href="{% routablepageurl page.get_parent.specific "entries_by_tag" tag.slug %}">{{ tag }}</a>
{% endif %}
{% with category=page.specific.category.first %}
{% if category %}
youriwims marked this conversation as resolved.
Show resolved Hide resolved
{% get_root_or_page as parent_page %}
{# If we have a "root" context variable, we know this card is generated on an index page (or index page subroute) #}
<a class="h6-heading d-block mt-3 mb-0" href="{% routablepageurl parent_page "entries_by_category" category.slug %}">{{ category }}</a>
{% endif %}
{% endwith %}
{% endif %}
Expand Down
16 changes: 16 additions & 0 deletions network-api/networkapi/wagtailpages/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import template

register = template.Library()


@register.simple_tag(takes_context=True)
def get_root_or_page(context):
root = context.get('root', None)
page = context.get('page', None)

if root:
return root.specific
elif page:
return page.get_parent().specific
youriwims marked this conversation as resolved.
Show resolved Hide resolved
else:
print("There is no root or page in templatetag get_root_or_page")
6 changes: 0 additions & 6 deletions source/sass/views/blog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@
}
}
}

.blog-card {
.main-tag {
text-transform: capitalize;
}
}