> TRIM would delete any whitespace from the string (tabs, newlines,
> spaces, ...). SPACELESS comes close as it will convert all the
> whitespace into just 1 space.

Should TRIM delete *all* whitespace, or just leading/trailing 
whitespace?  Trim functions usually just remove leading/trailing 
whitespace.

> {% block data %}{% spaceless %}{{ story.tease }}{% endspaceless %}
> {%endblock %}

You may be able to get away with simply using

   {{ story.tease.strip }}

If you need to remove *all* whitespace, not just the 
leading/trailing whitespace, you'll have to create your own 
filter to do it.  However, it's a fairly simple filter process:


import re
from django.template.defaultfilters import stringfilter
from django import template
register = template.Library()
whitespace_re = re.compile(r'\s')

@register.filter(name='remove_whitespace')
@stringfilter
def remove_whitespace(s):
     return whitespace_re.sub('', s)


If the above "{{ story.tease.strip }}" doesn't work for some 
reason (because "tease" is an object rather than a string, most 
likely), you can create a filter out of it the same way, only using

@register.filter(name='strip')
@stringfilter
def strip(s):
     return s.strip()

Either of these should then be usable as

   {{ story.tease|strip }}
or
   {{ story.tease|remove_whitespace }}

You can learn all about creating custom filters at

http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters

-tim





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