Login

AddThis Social Networking TemplateTag

Author:
yeago
Posted:
January 2, 2009
Language:
Python
Version:
1.0
Tags:
template-tag add-this social-networking
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. Add extra form elements in your contib admin by sergejdergatsjev 6 years, 9 months ago
  2. A dict template tag by Batiste 7 years, 4 months ago
  3. Unobtrusvie Foldable Admin Interface by whiteinge 7 years, 7 months ago
  4. Add special field lookups to the Admin list_filter display by whiteinge 7 years, 7 months ago
  5. Template tags to integrate with modconcat by matthanger 6 years, 1 month 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.