| 1 |
{# Basic extension of a common file #} |
| 2 |
{% extends "base_file.html" %} |
| 3 |
|
| 4 |
{% block title %}{{ section.title }}{% endblock %} |
| 5 |
|
| 6 |
{% block content %} |
| 7 |
<h1>{{ section.title }}</h1> |
| 8 |
|
| 9 |
{# For loop example #} |
| 10 |
|
| 11 |
{% for item in item_list %} |
| 12 |
<h2> |
| 13 |
<a href="{{ item.get_absolute_url }}"> |
| 14 |
{{ item.text }} |
| 15 |
{{ item.other_text|upper }} |
| 16 |
</a> |
| 17 |
</h2> |
| 18 |
<p>{{ story.longer_text|truncatewords:"100" }}</p> |
| 19 |
{% endfor %} |
| 20 |
{% endblock %} |
| 21 |
|
| 22 |
|
| 23 |
{# For loop example with specific content if empty #} |
| 24 |
|
| 25 |
{% for item in other_list %} |
| 26 |
<h2> |
| 27 |
{{ item.text }} |
| 28 |
</h2> |
| 29 |
{% else %} |
| 30 |
<h2> |
| 31 |
This list is empty |
| 32 |
</h2> |
| 33 |
{% endfor %} |
| 34 |
{% endblock %} |
| 35 |
|
| 36 |
|
| 37 |
{# if example #} |
| 38 |
|
| 39 |
{% if item_list %} |
| 40 |
Number of items: {{ item_list|length }} |
| 41 |
{% elif some_condition %} |
| 42 |
Show this text |
| 43 |
{% else %} |
| 44 |
Nothing to process |
| 45 |
{% endif %} |
| 46 |
|
| 47 |
{# This is a comment #} hello comment |
| 48 |
|
| 49 |
|
| 50 |
{# Translation example #} |
| 51 |
|
| 52 |
{% translate "Title" as title %} |
| 53 |
{% block content %}{{ title }}{% endblock %} |
| 54 |
|
| 55 |
|
| 56 |
{# Auto-escaping #} |
| 57 |
|
| 58 |
{% autoescape off %} |
| 59 |
Hello {{ name }} |
| 60 |
{% endautoescape %} |
| 61 |
|
| 62 |
|
| 63 |
{# Loading custom tags/libraries #} |
| 64 |
|
| 65 |
{% load humanize %} |