Skip to main content

A set of simple tools that will make your life easier in django templates. Based on great django-classytags library.

Installation

  1. Install the package

$> pip install django-template-goodies
  1. put “template_goodies” into INSTALLED_APPS.

Usage: render_with & def_block and use_block

This is sort of macro-like solution allowing you to define base template that looks always the same, and fill just a “block” inside it differently.

Assuming you have partial template person_wrapper.html:

{% load goodies %}
<div class="person-wrapper">
    <div class="first-name">{{ first_name }}</div>
    {% use_block "block" %}
</div>

You can use it in following way:

{% load goodies %}
{% render_with "person_wrapper.html" first_name="First" last_name="Last" %}
    {% def_block "block" %}
    <div class="last-name">{{ last_name }}</div>
    {% end %}
{% end %}

This invocation will substitude “{% use_block “block” %}” in person_wrapper.html with the contents within “{% def_block …. %}” and “{% end %}” insidee “render_with”. So the outcome of above will be more or less:

<div class="person-wrapper">
    <div class="first-name">First</div>
    <div class="last-name">Last</div>
</div>

Another example with tables, table.html:

{% load goodies %}
<table class="{{ opts.table_class }}">
    <thead>
        <tr>
            {% use_block "headers" %}
        </tr>
    </thead>
    <tbody>
        {% for row in object_list %}
        <tr>
            {% use_block "row" %}
        </tr>
        {% endfor %}
    </tbody>
</table>

can be used in following way:

{% render_with "table.html" object_list=people %}{% def_block "headers" %}
    <td>ID</td>
    <td>First name</td>
    <td>Last Name</td>
    <td>Age</td>
{% end %}{% def_block "row" %}
    <td>{{ forloop.counter }}</td>
    <td>{{ row.first_name }}</td>
    <td>{{ row.last_name }}</td>
    <td>{{ row.age }}</td>
{% end %}{% end %}

Usage: dict

Updates or creates dictionary inside template. You can use all kinds of filters on variable if you need:

{% load goodies %}

{% dict opts name="first"|title %}
{% dict opts last_name="last" value=opts.name %}

{{ opts.first }} - {{ opts.last_name}} || {{ opts.value }}

The outcome will be more or less following:

First - last || first

Requirements

  • django-classytags

Authors

Release files for django_template_goodies 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django_template_goodies 0.1.5
File Size Uploaded
django_template_goodies-0.1.5.tar.gz 2.9 kB Details

Release files / django_template_goodies-0.1.5.tar.gz

Download URL django_template_goodies-0.1.5.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
415f322e8ba9a69ff18a4a698928a12ea654541ae1ba3493950472d41cf05f79
BLAKE2b-256 checksum
How to use checksums
d02350962757f1de9d7cd66fe7ed61ca965169d032af24a2a7cc4da05da3e371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.5 This release

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page