Snippet List
Similar to `{% spaceless %}`, but only removes spaces followed by a special marker (`&nosp;`).
Helps keeping proper indentation:
{% skipspaces %}
Lots of coffee
{% if from_brazil %}
from Brazil
{% else %}
from Columbia
{% endif %}
{% if tea %}&nosp;, some tea{% endif %}
and a cake.
{% endskipspaces %}
Otherwise you'd have to write it in one looong line or get used to living with spaces before commas :)
NB the marker itself is stripped from rendered html as well.
- spaceless
- whitespace
- skip
- spaces
Tightens up response content by removed superflous line breaks and whitespace.
By Doug Van Horn
---- CHANGES ----
v1.1 - 31st May 2011
Cal Leeming [Simplicity Media Ltd]
Modified regex to strip leading/trailing white space from every line, not just those with blank \n.
---- TODO ----
* Ensure whitespace isn't stripped from within <pre> or <code> or <textarea> tags.
- middleware
- strip
- whitespace
This is a custom block tag and is used like this:
{% load whitespaceoptimize %}
{% whitespaceoptimize "css" %}
/* CSS comment */
body {
color: #CCCCCC;
}
{% endwhitespaceoptimize %}
And when rendered you get this output:
body{color:#CCC}
To install it, download the snippet and call it `myapp/templatetags/whitespaceoptimize.py`. (Make sure you have a `__init__.py` in the `templatetags` directory)
You need to download and install [slimmer](http://www.issuetrackerproduct.com/Download#slimmer) and put on your Python path.
The block tag can be used for `javascript` and `html` as well as `css`. You can also let it guess the format; this would work for example:
{% whitespaceoptimize %}
<table>
<tr> ...
{% endwhitespaceoptimize %}
...but this would just replicate the functonality of the [built-in spaceless tag](http://docs.djangoproject.com/en/dev/ref/templates/builtins/#spaceless)
- tag
- block
- whitespace
- slimmer
3 snippets posted so far.