Snippet List
Template filter that truncates the text when it exceeds a certain number of characters.
It deletes the last word only if partial.
Adds '...' at the end of the text, only if truncated.
Examples (text == 'Lorem ipsum dolor sit amet', len(text) == 26)
{{ text|truncatewords_by_chars:30 }}
'Lorem ipsum dolor sit amet'
{{ text|truncatewords_by_chars:25 }}
'Lorem ipsum dolor sit...'
{{ text|truncatewords_by_chars:21 }}
'Lorem ipsum dolor sit...'
{{ text|truncatewords_by_chars:20 }}
'Lorem ipsum dolor...'
By Davide Muzzarelli
- filter
- template-filter
- truncate
- truncatewords
Template filter that divides a list into an exact number of columns.
The number of columns is guaranteed.
Example (list == [1,2,3,4,5,6,7,8,9,10]):
{% for column in list|columns:3 %}
<ul>
{% for item in column %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endfor %}
Result:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
<ul>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
By Davide Muzzarelli
- filter
- template-filter
- list
- columns
Often I want to call a custom manager method in the template, something like Snippet.objects.get_latest(). I hate writing custom templatetags to do all that work, so instead I've written a filter that will work for any. Here's how I use it:
{% for snippet in "cab.snippet"|call_manager:"top_rated"|slice:":5" %}
Improved version of my snippet #1346. Now works correctly with multiple usernames and hash tags.
Both twitter usernames and hashtags are converted into links to twitter profiles and twitter search.
Updated, forgot about underscores in usernames.
- template-filter
- twitter
- hash-tag
- at-reply
A filter that changes a preparsed date from [Ultimate Feedparser](http://www.feedparser.org/) to a regular datetime instance.
Now you can -for example- pass a feed parsed by feedparser to a template and do this:
{% for item in feed.entries %}
Title: {{ item.title }}<br />
Date: {{ item.updated_parsed|feedparsed|date:"Y-m-d" }}
{% endfor %}
- template-filter
- datetime
- date
- feedparser
Generate QR Code image from a string with the Google charts API
http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes
Exemple usage in a template
{{ my_string|qrcode:"my alt" }}
will return the image tag with
* src: http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=my_string&choe=UTF-8
* alt: my alt"
- filter
- template-filter
- filters
- template-filters
- qr-code
- qr-codes
Couldn't get the original to work, and wanted more functionality (scale on x or y coordinates)
<img src="{{ object.image.url }}" alt="original image">
<img src="{{ object.image|thumbnail:"250w" }}" alt="image resized to 250w x (calculated/scaled)h ">
<img src="{{ object.image|thumbnail:"250h" }}" alt="image resized to (calculated/scaled)w x 250h h ">
<img src="{{ object.image|thumbnail:"250x200" }}" alt="image resized to 250wx200h ">
<img src="{{ object.image|thumbnail }}" alt="image resized to default 200w (or whatever you default it to) format">
Original http://www.djangosnippets.org/snippets/192/
Adapted http://www.djangosnippets.org/snippets/955/
Sampled From:
http://batiste.dosimple.ch/blog/2007-05-13-1/
http://vaig.be/2008/05/17/stdimagefield-improved-image-field-for-django/
- template
- filter
- image
- template-filter
- thumbnail
- templatetags
UPDATED:
This now supports an argument for the initial header level.
This is a modified version of `django.contrib.markup` that allows you to highlight code via [pygments](http://pygments.pocoo.org/). The code block can be used as:
`Here's a paragraph, and a code example:
.. code:: language
*insert code here*
continue with your normal document.`
Setup:
Insert the snippet into `mysite/templatetags/rest.py`, then add `mysite` to your installed apps in `settings.py`.
In your template, `{% load rest %}` and `{{ mycontent|rest }}`.
- pygments
- rest
- restructured-text
- template-filter
14 snippets posted so far.