[Templates] Wrap text in an HTML tag

Josh Rosenbaum josh at infogears.com
Mon Feb 11 17:09:03 GMT 2008


Ronald J Kimball wrote:
> I'm trying to figure out the best way to wrap part of a string text in 
> an HTML tag.  The string will be the result of calling 
> Catalyst.localize(), using the quant command for pluralization.
> 
> For example:
> 
>    [% Catalyst.localize('You have [quant,_1,new message].',
>                         new_message_count) %]
> 
> Output:
> 
>    You have 2 new messages.
> 
> Desired:
> 
>    You have <span class="highlight">2</span> new messages.
> 
> I looked at the replace() filter, but the replace string is a literal 
> string, so [% ... | replace('\d+', '<span class="highlight">$1</span>') 
> doesn't work.
> 
> It seems I'll need to create a custom filter to handle this, but I was 
> curious if anyone else had a suggestion.

Hi Ronald,

The replace filter should work fine with backrefs if you're using a newer version of TT. (I believe 2.14a or above.)

-- Josh



More information about the templates mailing list