Skip to content

Instantly share code, notes, and snippets.

@joshcartme
Created April 9, 2015 16:48
Show Gist options
  • Save joshcartme/bcdda75f1607890587ca to your computer and use it in GitHub Desktop.
Save joshcartme/bcdda75f1607890587ca to your computer and use it in GitHub Desktop.

index.html

{% include "teaser.html" %}

teaser.html

{% load page_teaser_tags keyword_tags mezzanine_tags i18n %}

{% block page_teaser %}
{% page_teaser "about-us" as teased_page %}
{% if teased_page %}
{{ teased_page.description|truncatechars_html:50|safe }}
{% endif %}
{% endblock %}

page_teaser_tags.py

from __future__ import unicode_literals

from mezzanine.pages.models import Page
from mezzanine import template

register = template.Library()

@register.as_tag
def page_teaser(page=''):
    """
    return the requested page
    usage
    {% page_teaser page="about-us" as page_teased %}
    """
    if page:
      pages = Page.objects.published()
      try:
          return pages.filter(slug=page)
      except page_teased.DoesNotExist:
          return None
    return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment