Login

Tag "spaceless"

Snippet List

spaceless_json

Now you can format and compress json-data in django template

  • django
  • templatetag
  • json
  • spaceless
  • formatting
  • application/id+json
Read More

Spaceless all HTML pages

This middleware remove all space between tags and line break of all HTML pages. Use a standard Django method. Set *force_spaceless* for dev. purpose.

  • middleware
  • optimization
  • spaceless
Read More

Skip only specified spaces

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
Read More

Plaintext format (advanced spaceless)

A template loader useful for writing templates with carefully controlled newlines and spaces while retaining readable template source code formatting. Start the template with PTFTAG (`{#ptfable#}`, here) to allow it to be processed. Common problems with doing it to most templates as-is is use of newlines to separate words and multiple spaces between tags where spaces are still needed (which is problematic with `spaceless` tag as well). Currently intended as a template loader wrapper, and is suggested to be used with cached loader. Example settings.py configuration: _lp = lambda lo, *ar: (lo, ar,) # loader, arguments TEMPLATE_LOADERS = ( _lp('django.template.loaders.cached.Loader', # cache _lp('ptf.template.ptftemplateloader.Loader', # ptf 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', #'django.template.loaders.eggs.load_template_source' ), # ptf ), # cache ) (change `ptf.` to wherever in python path you've put it). You might also need couple of simple template tags for explicitly inserting newlines or whitespaces: def br(): return "\n" br = register.simple_tag(br) # XHTML-XMPP-template compatible. def brx(): return "<br />\n" brx = register.simple_tag(br) def ws(): return " " ws = register.simple_tag(ws) .

  • spaceless
  • ptf
Read More

Smart Spaceless

This 'smart_spaceless' template tag is a replacement for Django's built-in 'spaceless'. If settings.DEBUG = True, spaces will not be removed to make debugging your template code easier. When DEBUG = False, spaces will be removed. Happy coding!

  • template
  • spaceless
  • template tag
  • remove spaces
  • template tags
Read More

smart spaceless

Just like `{% spaceless %}`, except a single space is preserved between two inline tags (such as `<a>`, `<em>`, and so on). This lets you use the tag on running text without fear of running two spans of styled text together incorrectly.

  • tag
  • spaceless
Read More

really spaceless (trim spaces at line start)

This tag is meant to override the current implementation of '{% spaceless %}' tag and remove spaces at the beginning of a line too. I.e. a template like this: <div> <div>useless space up front</div> </div> will become this `<div>` `<div>useless space up front</div>` `</div>` All the other behaviour of spaceless stays the same! Put this in your app/name/templatetags/tags.py And if you want it to override the default "spaceless"-tag to the following from django.template import add_to_builtins add_to_builtins('app.name.templatetags.tags')

  • template
  • tag
  • trim
  • spaceless
Read More

7 snippets posted so far.