Silk icon tags

 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. table with n items per row using custom modulo tag by elgreengeeto 4 years, 5 months ago
  2. Partial templates, combine with and include by koblas 3 years, 1 month ago
  3. Easy Conditional Template Tags by fragsworth 3 years, 11 months ago
  4. Mod to allow simple_tag to access context by leaf 4 years, 7 months ago
  5. Boolean Image Flag TemplateTag by MichaelAnckaert 4 years, 4 months ago

Comments

(Forgotten your password?)