Login

Silk icon tags

Author:
Hangya
Posted:
September 1, 2010
Language:
Python
Version:
1.2
Score:
4 (after 4 ratings)

This simple template tag can be used to add famfamfam's silk icons easily to any element in your template.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# icons.py by Hangya
#
# Add this to CSS:
# .icon { padding-left: 20px; background-repeat: no-repeat;}
#
# use at least 20px line-height for best experiences
#
# Download icons from http://www.famfamfam.com/lab/icons/silk/
# Upload them to your MEDIA_URL's icons subdirectory.
#
# Template usage:
# {% load icons %}
#
# <a href="/login/" {% icon 'door_in' %}>Login</a>
# <h2 {% icon 'user' %}>{{ user.username }}</h2>
# <p>Please subscribe to our <span {% icon 'feed' %}>RSS feed</span>.</p>
# <ul><li {% listicon 'bullet_picture' %}>Item</li></ul>
# etc.

from django import template
from django.conf import settings

register = template.Library()

def icon(icon_name):
  return 'class="icon" style="background-image:url('+settings.MEDIA_URL+'/icons/'+icon_name+'.png);"'
register.simple_tag(icon)

def listicon(icon_name):
  return 'style="list-style-image:url('+settings.MEDIA_URL+'/icons/'+icon_name+'.png);"'
register.simple_tag(listicon)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 4 weeks ago

Comments

Please login first before commenting.