On Oct 13, 3:41 am, Goon <[EMAIL PROTECTED]> wrote:

> Ok, but let's say I have a template like {{for x in y}}, and I would
> like the x's seperated by commas, but I don't want a comma after the
> last one?  or better yet cut off after the first 100 characters with a
> "..."

The key here is that this sort of logic _can_ be accomplished but it's
done by pushing the logic itself into Python code that's related to
the template - filters and tags. There's a lot of built-in ones
(http://www.djangoproject.com/documentation/templates/) and you can
accomplish both of your examples by applying included template filters
like so:

{% for x in y %}
{{ x }}{% if not forloop.last %},{% endif %}
{% endfor %}

Of course, if you're familiar with Python at all you might recall the
string join method; that's here too and is used for exactly this
purpose. So you can actually do:

{{ y|join:"," }}

As for truncating a string, you could use slice as previously noted:

{{ y|slice:":100" }}...

Basically, you just need to become familiar with the tools available -
there's a lot that can be done with them. If you find a need for
something the builtins don't accomplish by themselves or jointly, you
can easily write your own. Again, the idea being to push non-simple or
non-presentation-oriented logic into Python code that *doesn't* live
in the template - separating the layers, as it were. There's plenty of
documentation on it on the site and on blogs and here on the list as
well, if you ever get stuck :)

Regards,
Jeff


--~--~---------~--~----~------------~-------~--~----~
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