That worked, except for a couple of errors. Revised version (in case
it ever helps someone else):

from django.template import Library
register = Library()

@register.filter

def spannedstring(value):
        """ adds span around first half of string """
        words = value.split()
        halfwords = len(words)/2
        firsthalf = words[:halfwords]
        lasthalf = words[halfwords:]
        return '<span class="firsthalf">'+ ' '.join(firsthalf) + '</
span> '+ ' '.join(lasthalf)


On Jun 14, 12:50 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> OK, I tracked down truncatewords, and I'm thinking of something like
> this:
>
> def spanned_string(value):
>         """ adds span around first half of string """
>         words = s.split()
>         halfwords = len(words)/2
>         firsthalf = words[halfwords:]
>         lasthalf = words[:halfwords]
>         return <span>+ ' '.join(firsthalf) + </span>+ ' '.join(lasthalf)
>
> On Jun 14, 12:23 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > What I want to do is take the number of words, divide by 2 (and round
> > down a whole number), then apply a span to the first half.
>
> > I tried to find truncatewords, as I figured that would be a good
> > starting point (at least seeing how to count words), but I can't seem
> > to track it down.
>
> > Any help appreciated. Thanks.


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