1 2 3 4 5 6 7 8 9 10 11 12 | from django import template
register = template.Library()
@register.filter
def dom_id(el, prefix=None):
"""
{{book|dom_id}} # book_1
{{book|dom_id:'prefix'}} # prefix_book_1
"""
return '_'.join([part for part in [prefix, el._meta.module_name, str(el.id)] if part])
|
More like this
- sql to dict by amitu 2 years, 10 months ago
- html helpers for images and links by buriy 4 years, 4 months ago
- Choices helper by jacobian 2 years, 6 months ago
- Generating Taconite command documents by desfrenes 3 years, 9 months ago
- sqltojson by amitu 2 years, 10 months ago
Comments
For people who wonder what's RoR dom_id : it's used to generate an unique ID in HTML template. e.g.
<img id="{{ book|dom_id }}" src="..." />#