Login

Tag "break"

Snippet List

Filter to add zero-width space to break up long words

If you have long words (no spaces) that are so long that it's messing up your design, add a 0-width space in the word every X chars. Usage: Step 1. Inside your app's directory, create dir called 'templatetags'. In that directory, create a .py file (say 'app_extras.py'). Make sure you make this a python module, make an empty the init .py (with the 2 underscores on each side). Step 2. Inside template (make sure app is on INSTALLED_APPS list in settings.py): {% load app_extras %} Step 3. Enjoy! {{ some_long_word_with_no_breaks|zerowidthspace_separator:25 }}

  • wordwrap
  • wordbreak
  • word-break
  • long-words
  • break
  • long-lines
  • wrap
  • char-break
Read More

Continuing and breaking from loops in Django templates

This snippet makes Django templates support `break` and `continue` in loops. It is actually more powerful than the respective Python statements as it allows breaking and continuing from an outer loop, not just the innermost. `break` and `continue` are implemented as template filters, with the input value being the loop variable. For example, to break from the current `for` loop use `forloop|break`, and to continue from the next outer loop use `forloop.parentloop|continue`. The implementation monkeypatches Django (specifically Nodelist and ForNode) and has been tested on v1.2 with Python 2.6.

  • template
  • loop
  • break
  • continue
Read More

2 snippets posted so far.