getting the related entries with a templatetag using django-tagging

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{% block related %}
<div id="related-posts"><h2>{% trans "Related posts" %}</h2>
{% for tag in object.get_tags %}
	{% tagged_objects tag in blog.Post as relatedItems %}
	{% if relatedItems|length_is:"0" %}
	{% else %}
	<h3>{{ tag }}</h3>
	<ul>
	{% for relatedItem in relatedItems|slice:":3" %}
	<li><a href="{{ relatedItem.get_absolute_url }}">{{ relatedItem.name|typogrify }}</a></li>
	{% endfor %}
	</ul>
	{% endif %}
{% endfor %}
</div>
{% endblock %}

More like this

  1. Class Feeds DRY TemplateTag by gmandx 3 years ago
  2. Create new variables in templates by jmrbcu 5 years, 4 months ago
  3. PyIf Template Tag (Conditional Tag) by nstrite 6 years, 2 months ago
  4. Private Context Decorator by acdha 3 years, 9 months ago
  5. django-tagging clouds template tag by skam 6 years, 1 month ago

Comments

(Forgotten your password?)