Thank you Oliver for your answer.

 On 7 Okt., 22:19, olivier <[EMAIL PROTECTED]> wrote:
> Calling a template seems a little bit overkill.

Of course. But I just write some stuff to get my grip on Python again,
haven't used it for a long time. I grabbed the newest version of
"Learning Python" and started to play around. I wanted to use Jinja
because it's a lot like Django (which I'm looking forward to use as
soon as i finished the Python book) but can be used standalone without
any hassle (just easy_install and import).

On 7 Okt., 22:19, olivier <[EMAIL PROTECTED]> wrote:
> ... should the annotation tag be written if track.annotation is empty ?)

If the tag is set in the YAML file, it should be written. I guess it
makes no sense to write empty tags... but it does no harm either (or
does it?). So I just check for all allowed tags and if they are set,
they are written, wether or not they are empty.

On 7 Okt., 22:19, olivier <[EMAIL PROTECTED]> wrote:
> I don't like though the {%- if tag in playlist %} syntax which, I
> guess, invokes some jinja magic and translates to something  like
> getattr(playlist, tag, None) or hasattr(playlist, tag), but it's not
> that clear by reading the doc and your code which one is used (and
> which one you want : should the annotation tag be written if
> track.annotation is empty ?)

I do: print tmpl.render({"playlist": playlist})

Well playlist is a dictionary containing the tag-value pairs, parsed
from the corresponding YAML file. In the template i want to itterate
over a list of allowed tags and if the tag is present in the context,
print it. What would be the best way to do this with Djangos template
system?

I just scribbled together something in Jinja because i want to play
around and ended up with this (probably messy stuff):

    {%- for tag in ['title', 'creator', 'annotation', 'info', 'image',
'location', 'identifier', 'date', 'license', 'attribution'] %}
    {%- if tag in playlist %}
    <{{ tag }}>{{ playlist[tag] }}</{{ tag }}>
    {%- endif %}
    {%- endfor %}

Because i found no way, how i could access the variables from the
template (well locals() shows them, dir() too, but i could'nt access
them) i wrapped them in a second dict with "playlist": playlist, so i
could do "if tag in playlist" and "playlist[tag]".





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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