I've searched pretty much everywhere and I still can't get my simple
template tag working.

It's supposed to simply return a list of strings which I can output in
a template for loop. Currently it takes no parameters but eventually
I'd like to pass it a string to format the URL as well however it
doesn't seem to be rendering. Here's the tag code:

import datetime
from django.template import Library, Node

register = Library()

class DaysListNode(Node):
        def render(self, context):
                today = datetime.date.today()
                days_list = []
                for i in range(7):
                        day_delta = datetime.timedelta(days=i)
                        the_date = today + day_delta

                        # Locale's abbreviated weekday name.
                        day_name = the_date.strftime("%a")

                        # Day of the month as a decimal number [01,31]
                        day_num = the_date.strftime("%d").lstrip("0")

                        days_list.insert(i, day_name + '<br />' + day_num)

                context['days_list'] = days_list
                return ''

def calendar_days(parser, token):
        return DaysListNode()

register.tag('calendar_days', calendar_days)


And here's the way I'm calling it in the template:

{% load calendar_days %}
... lots of XHTML

<ul class="date">
        {% for day in calendar_days.days_list %}
        <li class="{% if forloop.first %}active{% endif %}"><a href="#">
{{ day }}</a></li>
        {% endfor %}
</ul>

It doesn't seem to work if I put {% for day in calendar_days %} or {%
for day in days_list %} either.

Any help would be appreciated,

Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to