Login

Tag "with"

Snippet List

Partial templates, combine with and include

This snippet adds simple partial support to your templates. You can pass data to the partial, and use it as you would in a regular template. It is different from Django's {% include %}, because it allows you to pass a custom variable (context), instead of reusing the same context for the included template. This decouples the templates from each other and allows for their greater reuse. The attached code needs to go into templatetags folder underneath your project. The usage is pretty simple - {% load ... %} the tag library, and use {% partial_template template-name data %} in your template. This will result in template passed as template-name to be loaded from your regular template folders. The variables are passed in a with compatiable syntax, eg. VAR as NAME and VAR as NAME No limitations on the number of variables passed.

  • template
  • templates
  • partial
  • with
  • include
  • partials
Read More

WithTag Tag

Set a context variable with the returned value by any templatetag. Useful for example in order to use url templatetag inside blocktrans: ` {% withtag url my_app.views.my_view as my_view_url %}` ` {% blocktrans %}` ` Click <a href="{{ my_view_url }}">here</a>` ` {% endblocktrans %}` ` {% endwithtab %}` Or with include templatetag: ` {% withtag include "js_template.js" as js_template %}` ` {{ js_template }}` ` {% endwithtab %}` It works properly with your own custom templatetags.

  • templatetag
  • with
  • withtag
  • with_tag
Read More

2 snippets posted so far.