0

Continuing from here, I'm trying to create a global nav using values in a model for the link in the nav. I've been pointed in the right direction with inclusion tags, but I'm still not able to work with the objects my inclusion tag returns...I just get blank. I have a simple model called Division:

class Division(models.Model):
    DivisionAbbrev = models.CharField(max_length=20)

I have included the template navigation.html in base.html. I am trying to use navigation.html to show the different DivisionAbbrev, using an inclusion_tag. In current_tags.py I create a dictionary of each object in Division:

current_tags.py

from django import template
from libs.display.models import Division
register = template.Library()
@register.inclusion_tag('display/navigation.html')
def get_navigation(self=None):
        return {
                'navigation': Division.objects.all(),
        }

Then in navigation.html:

{% load current_tags %}
<p>Test</p> # This prints, so I know navigation.html is included correctly
{% for item in get_navigation %} # This doesn't print anything
<p>{{ item.DivisionAbbrev }}</p>
{% endfor %}

base.html

{% include 'display/navigation.html' %}
Community
  • 1
  • 1
nshaas
  • 114
  • 2
  • 11
  • 1
    This blog should help you: http://www.mechanicalgirl.com/view/custom-template-tags-in-django/ – karthikr Mar 23 '14 at 18:39
  • 1
    This doesn't make any sense. You can't call the template tag inside the very template that's being rendered by the template tag. – Daniel Roseman Mar 23 '14 at 20:11
  • Wow...that explains everything: "You can't call the template tag inside the very template that's being rendered by the template tag". Didn't realize the template tag was rendering the template. That article definitely help. Thanks...problem solved! – nshaas Mar 23 '14 at 22:54

0 Answers0