Last active
August 29, 2015 13:59
-
-
Save SmileyChris/10611277 to your computer and use it in GitHub Desktop.
flatpages template tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@register.assignment_tag | |
def flatpages(a, b, *order_first): | |
""" | |
Get the flatpages, optionally with specific ones ordered first. | |
Usage:: | |
{% flatpages '/home/' '/about/' as flatpages %} | |
{% for flatpage in flatpages %}...{% endfor %} | |
""" | |
flatpages = list(FlatPage.objects.all()) | |
flatpages.sort(key=lambda page: (order_first.index(page.url) if page.url in order_first else len(flatpages)) | |
return flatpages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment