Answer the question
In order to leave comments, you need to log in
jinja2 template logic?
Good afternoon. Started learning Jinja2 templating engine. And I have some questions, namely:
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/reset.min.css' %}"/>
<link rel="stylesheet" href="{% static 'css/main.css' %}"/>
</head>
<body>
{% block header %}{% endblock %}
{% block nav %}{% endblock %}
{% block content %}{% endblock %}
{% block footer %}{% endblock %}
</body>
</html>
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block header %}
{% include "layouts/header.html" %}
{% endblock %}
<header>
<p>{{ text }}</p>
</header>
Answer the question
In order to leave comments, you need to log in
This is how it turns out to pass the value of a variable.
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/reset.min.css' %}"/>
<link rel="stylesheet" href="{% static 'css/main.css' %}"/>
</head>
<body>
{% block header %}{% endblock %}
<script src="{% static 'js/main.js' %}"></script>
</body>
</html>
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block header %}
{% with txt='1' %}
{% include "layouts/header.html" %}
{% endwith %}
{% endblock %}
<header>
<p>{{ txt }}</p>
</header>
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block header %}
{% with txt='1' txt2='2' txt3='3' %}
{% include "layouts/header.html" %}
{% endwith %}
{% endblock %}
<header>
<p>{{ txt }}</p>
<p>{{ txt2 }}</p>
<p>{{ txt3 }}</p>
</header>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question