Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

block Template Tag


Example

Define a section in a master template that should be replaced by a section in a child template:

<!DOCTYPE html>
<html>
<body>
<h1>Welcome</h1>

{% block userinfo %}
  <h2>Not registered yet</h2>
{% endblock %}

</body>
</html>
Run Example »

Definition and Usage

The block tag  has two functions:

  1. It is a placeholder for content.
  2. It is content that will replace the placeholder.

In master templates the block tag is a placeholder that will be replaced by a block in a child template with the same name.

In child templates the block tag is content that will replace the placeholder in the master template with the same name.

In the example above you see the content of a master template, it has a block called userinfo. This block will be replaced with a block called userinfo in a child template:

Example

This is a child template that refers to a master template via the extend tag:

{% extends "mymaster.html" %}

{% block userinfo %}
  <h2>John Doe</h2>
  <p>Explorer of life.</p>
{% endblock %}
Run Example »

Syntax

{% block name %}
  ...
{% endblock %}

Parameters

Value Description
name Specifies that name of the block.