Login

Dom ID

Author:
bmihelac
Posted:
November 18, 2009
Language:
HTML/template
Version:
Not specified
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. Bootstrap Accordian by Netplay4 5 years, 10 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
  4. Reusable form template with generic view by roldandvg 8 years, 11 months ago
  5. Pagination Django with Boostrap by guilegarcia 9 years, 1 month 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.