{% load my_utils %} should work

On Wed, Sep 3, 2008 at 11:46 AM, joune <[EMAIL PROTECTED]> wrote:

>
> Thanks Daniel..
>
> Sorry i'm a bit slow (i do this in my spare time)
>
> I tried what you said, and refered to the doc at
> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ for
> writing custom filters..
> so i wrote the code you suggested in my_utils.py, indide a
> templatetags directory along with an empty __init__.py
> then added
> {% load my_utils.py %}
> to my template before calling the new filter..
>
> but now i get a
> TemplateSyntaxError: 'my_utils' is not a valid tag library
>
> i've searched this forum again but people seem to be using either
> ready made tag libs or forgot the __init__.py, but nothing i could
> use...
>
> any idea from your side for what i could be doing wrong?
> by the way... i'm doing this inside google AppEngine.. i hope there's
> no restriction on custom tags!
>
> Thanks again,
> joune
>
>
>
>
> On Sep 1, 2:37 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
> > On Sep 1, 1:05 pm, joune <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > Hi all,
> > > I'm totally new to Django and i'm starting to play with templates...
> > > I have a list to display and a separate list of elements considered
> > > special;
> > > so i'd like to display the first list with a different style if the
> > > element is contained in the "specials list"
> >
> > > for instance:
> > > list = [ 'john', 'bill', 'robert', 'greg' ]
> > > specials = [ 'bill', 'greg' ]
> >
> > > then i wish i could use in the template:
> > > {% for name in list %}
> > > {% if name in specials %} <b>{{ name }}</b>
> > > {% else %} {{ name }}
> > > {% endif %}
> > > {% endfor %}
> >
> > > Unfortunately this 'if' syntax is not supported by the templating
> > > system.
> > > Neither can i call a function that would take name as an argument and
> > > return True or False.
> > > This seems a very basic use case (much simpler than many advanced
> > > template features such as 'regroup') yet I can't find the correct way
> > > to do this, so i believe i must have missed something..
> >
> > > Could someone please help me with this?
> > > Thanks.. (do not hesitate to ask precisions if my use case is not
> > > clear..)
> >
> > You can't do this with the built-in filters, but it's trivially easy
> > to write a custom filter that will do it. Something like (untested):
> >
> > from django import template
> > register = template.Library()
> >
> > @register.filter
> > def is_in(value, value_list):
> >     return value in value_list
> >
> > and in the template:
> >
> > {% if name|is_in:specials %}
> >
> > --
> > DR.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to