djangosnippets.org: Latest snippets tagged with 'include'https://djangosnippets.org/tags/include/2016-07-04T22:33:30.991335-05:00Raw include from static dir tag
2016-07-04T22:33:30.991335-05:00MikiSofthttps://djangosnippets.org/snippets/10574/<p>This is useful when you don't want to put any <code>{% verbatim %}</code> tag in the file(s) you're including within template(s) (because you want it/them completely raw) and when you want to load such file(s) from static dir(s), as native <code>{% include %}</code> tag can't achieve that (still).</p>
<p>Put the …</p>
Freely redistributableRelative paths for Django template tags 'extends' and 'include'.
2016-03-17T07:00:40.022829-05:00vb64https://djangosnippets.org/snippets/10558/<p><a href="http://stackoverflow.com/questions/671369/django-specifying-a-base-template-by-directory">The problem</a>: {% extends "./../base.html" %} won't work with extends.</p>
<p>It causes a lot of inconvenience, if you have an extensive hierarchy of django templates.
This library allows relative paths in argument of 'extends' and 'include' template tags. Relative path must start from "./"</p>
<p>Just write in your templates …</p>
Freely redistributablePartial Tag
2010-07-11T23:03:49.420317-05:00mnbayazithttps://djangosnippets.org/snippets/2104/<p>Lets you include another template and pass in named variables. Use like:
</p>
<pre><code>{% partial field_template field=form.city %}
</code></pre><p>If no key is specified, it will use "item" instead. You may pass in multiple variables as comma-separated key=value pairs.
</p>
Freely redistributable{% renderonce %} template tag
2010-06-13T04:59:42.033596-05:00corrrhttps://djangosnippets.org/snippets/2064/<p>This is in the spirit of php's include_once or a C preprocessor #ifndef. Kind of. As you might've guessed, the output of</p>
<pre><code>{% renderonce %}foo{% endrenderonce %}
{% renderonce %}foo{% endrenderonce %}
</code></pre>
<p>in a template will be a single 'foo'. I use it for js script tags personally, to prevent …</p>
Freely redistributableSilently-failing include tag
2010-06-10T10:00:05.213545-05:00brutassehttps://djangosnippets.org/snippets/2058/<p>This is the <code>local_settings.py</code> trick extended to Django templates.
</p>
<p>Sometimes you need to insert some arbitrary code in the HTML of the production site for external service integration like uservoice, typekit, google analytics... You don't want to put this code into source control because some other sites using the same …</p>
Freely redistributablePartial templates, combine with and include
2010-04-16T16:29:28.434195-05:00koblashttps://djangosnippets.org/snippets/1989/<p>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 …</p>
Freely redistributableSubdirectory and subcontext include template tag with examples
2010-03-19T08:03:59.321996-05:00t_rybikhttps://djangosnippets.org/snippets/1964/<p>In principle it's a DRY code of a template node that can be used for creating project-wide template-tags. These can be used to display conceptually common blocks in templates with applications specific looks and content. E.g.:</p>
<ol>
<li>
<p>application-specific info message,</p>
</li>
<li>
<p>model instances details in the list context,</p>
</li>
<li>
<p>login messages like 'Please …</p></li></ol>
Freely redistributableDecorate Template Tag (In-Line include and extend with local context)
2010-01-08T23:57:26.258009-06:00rhomberhttps://djangosnippets.org/snippets/1860/<p>I had an issue with the django templating system, where by if I included several different files at the same level on one template.. and all the included templates extended the same base template. It would render the defined blocks for the first inclusion for all. i.e. everything in the …</p>
Freely redistributableDjango Template "include_raw" tag
2009-08-13T15:42:25.831712-05:00wwu.housinghttps://djangosnippets.org/snippets/1684/<p>At WWU Housing, we started using the <a href="http://plugins.jquery.com/project/tempest">Tempest jQuery plugin</a> for javascript templating, which has the same {{ var }} syntax as Django's templating.</p>
<p>We wanted to be able to use the same templates in our server-side python and our client-side js, so we had to have a way of …</p>
Freely redistributableA templatetag to insert the output of another view (or local URL)
2009-06-17T04:20:32.206375-05:00jamesgpearcehttps://djangosnippets.org/snippets/1568/<p>Inserts the output of a view, using fully qualified view name (and then some
args), a or local Django URL.</p>
<pre><code>{% view view_or_url arg[ arg2] k=v [k2=v2...] %}
</code></pre>
<p>This might be helpful if you are trying to do 'on-server' AJAX of page
panels. Most browsers can call back to the …</p>
Freely redistributableurl extension mechanism
2009-04-16T13:40:19.600281-05:00showellhttps://djangosnippets.org/snippets/1444/<p>Executive summary: url "include" on steroids--granular extra parms and validate names in passing</p>
<p>We maintain multiple Django applications, and we use the excellent built-in include mechanism to allow one urls.py to borrow from another:</p>
<p>http://docs.djangoproject.com/en/dev/topics/http/urls/</p>
<p>If you scroll down to the section entitled "Passing extra options to include," you will …</p>
Freely redistributableLanguage-aware template inclusion
2009-02-25T10:37:20.816306-06:00bartTChttps://djangosnippets.org/snippets/1341/<p>Looks up for a template based on the template-name plus the current users language code. Loads the template and renders it with the current context.</p>
<p>Example::</p>
<pre><code>{% langinclude "foo/some_include.html" %}
</code></pre>
<p>Based on the users LANGUAGE_CODE, assumed we have 'de', it tries to render the template 'foo/some_include.html.de'. If that doesn't exists, …</p>
Freely redistributableMore flexible "Partial Template"
2009-02-06T18:05:42.173832-06:00robertrvhttps://djangosnippets.org/snippets/1313/<p>This is an extension of the snippet http://www.djangosnippets.org/snippets/1302/ to make it a bit more flexible and been able pass more than one parameter to our "Partial Template". To use it you can </p>
<p>{% partial_template template_name param1:variable1 param2:variable2 ... %}</p>
<p>or:</p>
<p>{% partial_template partials/mini_template.html item:data1 var2:"False" var3:"2*2" %}</p>
Freely redistributable"Partial Templates" - an alternative to "include"
2009-01-29T17:01:30.428473-06:00vigridhttps://djangosnippets.org/snippets/1302/<p>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 <code>{% include %}</code>, because it allows you to pass a custom variable (context), instead of reusing the same …</p>
Freely redistributableRandomized Include Tag
2008-12-05T10:51:36.275744-06:00justinlillyhttps://djangosnippets.org/snippets/1233/<p>a randomized version of {% include %}</p>
<p>{% rand_include "foo.html","bar.html","zot.html" %}</p>
Freely redistributable