Template tags

icekit.templatetags.icekit_tags.grammatical_join(l, initial_joins=', ', final_join=' and ')[source]

Display a list of items nicely, with a different string before the final item. Useful for using lists in sentences.

>>> grammatical_join(['apples', 'pears', 'bananas'])
'apples, pears and bananas'
>>> grammatical_join(['apples', 'pears', 'bananas'], initial_joins=";", final_join="; or ")
'apples; pears; or bananas'
Parameters:
  • l – List of strings to join
  • initial_joins – the string to join the non-ultimate items with
  • final_join – the string to join the final item with
Returns:

items joined with commas except ” and ” before the final one.

icekit.templatetags.icekit_tags.update_GET(parser, token)[source]

update_GET allows you to substitute parameters into the current request’s GET parameters. This is useful for updating search filters, page numbers, without losing the current set.

For example, the template fragment:

<a href="?{% update_GET 'attr1' += value1 'attr2' -= value2
'attr3' = value3 %}">foo</a>
  • adds value1 to (the list of values in) 'attr1',
  • removes value2 from (the list of values in) 'attr2',
  • sets attr3 to value3.

and returns a urlencoded GET string.

Allowed attributes are:

  • strings, in quotes
  • vars that resolve to strings

Allowed values are:

  • strings, in quotes
  • vars that resolve to strings
  • lists of strings
  • None (without quotes)

Note:

  • If a attribute is set to None or an empty list, the GET parameter is removed.
  • If an attribute’s value is an empty string, or [""] or None, the value remains, but has a "" value.
  • If you try to =- a value from a list that doesn’t contain that value, nothing happens.
  • If you try to =- a value from a list where the value appears more than once, only the first value is removed.
icekit.templatetags.icekit_tags.oembed(url, params='')[source]

Render an OEmbed-compatible link as an embedded item.

Parameters:url – A URL of an OEmbed provider.
Returns:The OEMbed <embed> code.

Returns a link to the admin URL of an object.

No permissions checking is involved, so use with caution to avoid exposing the link to unauthorised users.

Example:

{{ foo_obj|admin_link }}

renders as:

<a href='/admin/foo/123'>Foo</a>
Parameters:obj – A Django model instance.
Returns:A safe string expressing an HTML link to the admin page for an

object.

icekit.templatetags.icekit_tags.admin_url(obj)[source]

Returns the admin URL of the object.

No permissions checking is involved, so use with caution to avoid exposing the link to unauthorised users.

Example:

{{ foo_obj|admin_url }}

renders as:

/admin/foo/123
Parameters:obj – A Django model instance.
Returns:the admin URL of the object

Returns a link to the object. The URL of the link is obj.get_absolute_url(), and the text of the link is unicode(obj).

Example:

{{ foo_obj|link }}

renders as:

<a href='/foo/'>Foo</a>
Parameters:obj – A Django model instance.
Returns:A safe string expressing an HTML link to the object.