Login

Tag "template-tag"

Snippet List

copyright_since

**Example usage**: {% copyright_since 2008 %}, {% copyright_since 2009 %} **Output**: © 2008—2009, © 2009 Use this templatetag in your footer to achieve proper formatting of copyright notice.

  • datetime
  • date
  • template-tag
  • formatting
  • copyright
  • copyright-formatting
  • copyright-year
Read More

ifinlist template tag

I recently had to write a custom template tag which checks to see if a value exists in a list variable from within a Django template. This was my first ever attempt at writing a template tag so any feedback would be appreciated.

  • template-tag
  • if-in-list
  • if-value-in-list
Read More

AddThis Social Networking TemplateTag

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>

  • template-tag
  • add-this
  • social-networking
Read More

Conditional template parsing block

I'm developing a regionalization extension based on PostGIS and GeoDjango for a web-based LCA software. Because PostGIS (or PostgreSQL) is not available everywhere, we needed a way to fully disable the geographic extensions. Because of that, I set out to create a template block tag which only gets evaluated when GIS support is active and totally ignored (treated as a comment) otherwise. I had some problems getting my BoringNode to work (which should just pass the content through), so I've just used the AutoEscapeControlNode (why? Because it was the first usable class that jumped into my eye.) for this purpose.

  • template-tag
  • conditional-parsing
Read More
Author: mk
  • 0
  • 0

Boxes as template tags

It's a template tag used to create boxes with nested divs (useful to keep the templates DRY). For example: {% menubox titlevar %} Content here {% endmenubox %} will generate the html with the nested divs div class=box div class=box-outer div class=box-inner Headline Content /div /div /div [more detail on this blog post](http://pedro.valelima.com/blog/2007/sep/26/boxes-template-tags/)

  • template-tag
  • box
Read More

"for" template tag with support for "else" if array is empty

This is a customized version of the default `for` template tag which takes an optional `{% else %}` clause that will be displayed if the given array is empty. from django.template import * >>> t1 = Template(""" {% load mytags %} {% for athlete in athlete_list %} {{ athlete }} {% else %} No athlete in list! {% endfor %} """) >>> c1 = Context( {'athlete_list': ['me', 'myself', 'I'] }) >>> t1.render(c1) u'me myself I ' >>> c2 = Context({}) >>> t1.render(c2) u'No athlete in list!' If you want to automatically override the builtin `for` template-tag add it to the builtins: from django.template import add_to_builtins add_to_builtins('python.path.to.mytags')

  • template
  • tags
  • template-tag
  • templatetags
  • forloop
Read More

Hyperlink list filter

This is a simple filter that takes an object list and returns a comma-separated list of hyperlinks. I use it to display the list of tags in my blog entries. The function assumes the object has a `get_absolute_url()` method that returns the URL. In your template, write `{{ obj_list|hyperlink_list:"slug" }}` where `obj_list` is your object list and `"slug"` is the object's attribute that returns the link text.

  • filter
  • templatetag
  • links
  • template-tag
  • link
  • hyperlink
Read More

Clouds Tag

This is a simple template tag to create Tag Clouds. Based on the number of Posts (change the model_name according to your schema), Tags are provided different size ( most number of posts => most popular => and hence the largest. We create a property called cloudsize for each tag, which is an integer between minsize and maxsize. Check the example of sample template use here http://www.djangosnippets.org/snippets/472/

  • tag
  • template-tag
  • tagging
  • clouds
  • cloud
Read More

Cloud Tag template example

This is the example of a Django Template that makes use of the clouds example given in the link. It uses the simple CSS selector font-style which can be expressed as per centage. Check the code in http://www.djangosnippets.org/snippets/473/

  • tag
  • template-tag
  • tagging
  • clouds
  • cloud
Read More

Clouds Tag

This is a simple template tag to create Tag Clouds. Based on the number of Posts (change the model_name according to your schema), Tags are provided different size ( most number of posts => most popular => and hence the largest. We create a property called cloudsize for each tag, which is an integer between minsize and maxsize.

  • tag
  • template-tag
  • tagging
  • clouds
  • cloud
Read More

{% with %} template tag

Add a value to the context (inside of this block) for easy access. Provides a way to stay DRYer in your templates. **NOTE:** This tag is now in Django core, so if you have Django >0.96 (or SVN) then you do NOT need this.

  • template
  • template-tag
  • encapsulation
Read More

Markdown and Syntax Highlighting in Django

This is a [Django template tag](http://www.djangoproject.com/documentation/templates_python/#extending-the-template-system "Extending the template system") that renders an arbitrary block of text with Markdown and [Pygments](http://pygments.org "Syntax highlighter"). Use Markdown as usual, and when you have a code block to insert, put it inside `code` tags, with the language as the class: `<code class='python'>print "Hello, World"</code>` To use it in a template, first `{% load ... %}` the tag library, then `{{ content|render }}` your content. The tag takes one optional argument, to enable safe rendering in markdown. To use it, call `{{ content|render:"safe" }}`.

  • pygments
  • markdown
  • syntax-highlighting
  • template-tag
Read More

30 snippets posted so far.