Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created March 10, 2010 20:17
Show Gist options
  • Save jacobian/328320 to your computer and use it in GitHub Desktop.
Save jacobian/328320 to your computer and use it in GitHub Desktop.
##### yabl/entries/templatetags/entry_tags.py
from django import template
from yabl.entries.models import Entry
register = template.Library()
@register.inclusion_tag('entries/latest_snippet.html')
def latest_entries(num):
return {
'entries': Entry.objects.order_by('-pub_date')[0:num]
}
##### yabl/templates/entries/latest_snippet.html
<ul>
{% for e in entries %}
<li>{{ e }}</li>
{% endfor %}
</ul>
##### yabl/templates/base.html
...
<h1>Latest entries:</h1>
{% load entry_tags %}{% latest_entries 2 %}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment