Cheers to limodou for getting me thinking about this. The only problem with his implementation is that it doesn't support Django's "." syntax for accessing array/dict elements. In the Django style of allowing simple syntax for designers while allowing for greater flexibility, and less template duplication for conditionals that were previously impossible to represent in templates, I modified Django's built-in If tag.
This is an adaptation/enhancement to Django's built in IfNode {% if ... %} that combines if ifequal ifnotequal into one and then adds even more. This
Supports
1. ==, !=
2. not ....
3. v in (1,"y",z)
4. <=, <, >=, >
5. nesting (True and (False or (True or False)))
How to use it:
{% pyif i == 1 or (5 >= i and i != 7) and user.first_name in ('John', 'Jacob') %}
'Tis true.
{% else %}
'Tis false.
{% endif %}
I hope you like it.
- template
- tag
- templatetag
- if
- conditional
- ifequal
- ifnotequal
The loremipsum tag generates random content for use in mockups. It takes this content from Cicero's De finibus bonorum et malorum. By default you get a random number of paragraphs up to 6, but you can affect this behaviour by passing in parameters for quantity and units. Units can be "paragraphs" or "words"; the default is paragraphs. Quantity dictates the number of units returned.
If your django.conf.settings.TEMPLATE_DEBUG is True, then no output is returned, so you should be OK in the event you leave the tag in a production template.
Syntax:
{% loremipsum %}
{% loremipsum quantity="3" units="paragraphs" %}
By leaving the behaviour as random, you can see how your layout handles varying amounts of content. Handy, especially for multi-column pages. [Here's a stoopid site](http://lakes.knoxzilla.com/) where I'm playing with random text, pictures, business listings, etc.
I do plan to add a "corpus" parameter to allow you to put your own corpus between lorumipsum and endloremipsum tags and a template parameter to specify the corpus should come from a template, but this has suited me well thus far.
I knew that template in myght template system can receive some parameters just like a function. And I also want to implement this function in django template. So I finish a rough one, the code is pasted here. It just like include, but in order to distinguish with "include" tag, I call it "call". So you can use it:
{% call "some.html" %}
This way just like include tag, and the advanced way:
{% call "some.html" with "a" "b"|capfirst title="title1" %}
{% call "some.html" with "c" "d" title="title2" %}
So you can see, "call" tag can do like a python function, it can receive tuple parameters and key word parameters, just like the function:
def func(*args, **kwargs):pass
How to use it
===============
test_call.html
{% expr "limodou" as name %}
{% call "test/test_sub.html" with "a"|capfirst "b" title="title1" %}<br/>
{% call "test/test_sub.html" with "c" "d" title="title2" %}
expr is also a custom tag written by me. It'll calculate a python expression and save to result to a variable. In this case, the variable it "name".
test_sub.html
{% for i in args %}{{ i }}{% endfor %}
<h2>{{ title }}</h2>
<p>{{ name }}</p>
<h3>args</h3>
{{ args }}
<h3>kwargs</h3>
{{ kwargs }}
And you also can see, call tag will auto create args and kwargs context variables.
I hope this will be some useful.