Login

AddThis Social Networking TemplateTag

Author:
yeago
Posted:
January 2, 2009
Language:
Python
Version:
1.0
Score:
2 (after 2 ratings)

Code to add an 'AddThis' button to your blog posts.

Simply do:

{% add_this post.title post.get_absolute_url %}

Also, specify your ADD_THIS_USERNAME to your settings.

<!-- blog/add_this.html -->
<script type="text/javascript">var addthis_pub="{{ username }}";</script>
<a href="http://www.addthis.com/bookmark.php" onmouseover="return addthis_open(this, '', '{{ site.domain }}{{ url }}', '{{ site.name }} - {{ title }}')" onmouseout="addthis_close()" onclick="return addthis_sendto()">
<img src="http://s7.addthis.com/static/btn/lg-addthis-en.gif" width="125" height="16" border="0" alt="" style="border:0"/></a>
<script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#your/templatetag.py

@register.inclusion_tag('blog/add_this.html')
def add_this(url,title):
        from django.contrib.sites.models import Site
        site = Site.objects.get_current()

        from django.conf import settings
        username = settings.ADD_THIS_USERNAME
        return {'url': url, 'title': title, 'username': username, 'site': site }

More like this

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

Comments

kenbolton (on June 9, 2009):

the signature for the add_this() function is: (url,title)

the templatetag example has them reversed: {% add_this post.title post.get_absolute_url %}.

#

Please login first before commenting.