Filter: get
Actually, it's about six thoughts. I'll give you my quick thoughts
below, but if you're serious about discussing this stuff you'll want
to have a thread for each of 'em so that you can easily refer back to
the discussion later.
> Filter: get
This has been discussed ad nauseam in the past, and has been rejected
repeatedly. If you want to bring it up again, you'll need to review
the previous discussion and bring to the table something new.
> I couldn't find another way,
Here's two:
1. ``{% for key, value in dict.items %}``
2. Make your view provide data that's easier for a template to consume.
> Tag: ifstartswith
> I find this very useful in writing menus, navigation bars, etc. since
> I'm often checking whether the URL is within a given subdirectory.
This leads naturally to pretty scare feature creep. If we have
startswith, why not ifendswith? ifcontains? ifdoesntcontain?
ifcontainssomewhereinthemiddleafterthethirdcharacter?
There's a reason we support custom template tag libraries: they mean
this stuff doesn't have to go in core, and so the general feature
creep isn't a problem.
> Yes, I could usually sort the list before passing it into the
> template, but it's nice to be able to do it in the template at well!
Not only *could* you sort the list in the view, you *should* sort the
list in the view. That's what views are *for*.
Also, try ``{% for x in list reversed %}``.
----
Okay, I didn't mean to rain on your parade there, but I'm strongly
opposed to feature creep in the template language. If you can't
articulate why something *MUST* be a builtin -- why it Just Won't Do
to have it in an external library -- it's going to be very hard to
convince me to add it.
Jacob
What about allowing {{ d.'k' }} ? It's less typing, and maps more to
a dict lookup.
And, you could still do {{ d.'k'|default:'Hello' }} for a default value,
> Tag: ifstartswith
> I find this very useful in writing menus, navigation bars, etc. since
> I'm often checking whether the URL is within a given subdirectory.
I'm a fan of having more if tags, but am not a fan of having if tags that
require me to remember all of the suffixes. Perhaps a smarter if tag in
general would be better...
This has been discussed ad nauseam in the past, and has been rejected repeatedly.
It's in the footer that Google adds to every message:
> For more options, visit this group at
> http://groups.google.com/group/django-developers?hl=en
Jacob
A smarter "if" tag has already been proposed as a v1.2 feature, and I
think there is some support for it. However, "smarter" doesn't mean
"exposing everything that Python can do" - it just means clarifying
the syntax for some of the simple cases. ==, < >, and "in" are
possible candidates. "startswith" sounds a bit too much like "logic in
the template" feature creep to me.
Yours,
Russ Magee %-)