- May 13, 2014
- highlighting custom-template-tag
- 0 (after 0 ratings)
sterm is the search term. text is the result search text.
it will highlight every matched search term in search result. please define your own .yellow css class.
1 2 3 4 5 6 7 8 9
@register.filter(needs_autoescape=True) def highlight(text, sterm, autoescape=None): if autoescape: esc = conditional_escape else: esc = lambda x: x pattern = re.compile('(%s)' % esc(sterm), re.IGNORECASE) result = pattern.sub(r'<strong class="yellow">\1</strong>',text) return mark_safe(result)
More like this
- Tags & filters for rendering search results by exogen 7 years, 10 months ago
- highlight text by nathantn 1 year, 5 months ago
- jQuery ajax search by Peidor 8 years, 11 months ago
- Middleware to detect visitors who arrived from a search engine by exogen 8 years, 9 months ago
- Text Highlighting Filter by girasquid 7 years, 2 months ago