Login

Silk icon tags

Author:
Hangya
Posted:
September 1, 2010
Language:
Python
Version:
1.2
Tags:
templatetags icons silk
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. icon shortcut - pseudohtml tag with attribute merging and variables resolving by wiz 4 years, 9 months ago
  2. Boolean Image Flag TemplateTag by MichaelAnckaert 6 years, 2 months ago
  3. fancy_if by Scanner 7 years, 10 months ago
  4. "If in" template tag by andrew 6 years, 10 months ago
  5. ImageField for admin with thumbnail by semente 5 years, 8 months ago

Comments

Please login first before commenting.