Login

Dom ID

Author:
bmihelac
Posted:
November 18, 2009
Language:
HTML/template
Version:
Not specified
Tags:
templatetag templatefilter dom_id
Score:
0 (after 0 ratings)

Helper for identifing records in views similiar to rails dom_id helper.

 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

  1. sql to dict by amitu 6 years ago
  2. sqltojson by amitu 6 years ago
  3. Choices helper by jacobian 5 years, 7 months ago
  4. html helpers for images and links by buriy 7 years, 5 months ago
  5. executesql by amitu 6 years ago

Comments

romain-hardouin (on November 20, 2009):

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="..." />

#

Please login first before commenting.