{% if cond %}

This is not HTML. It's Jinja2 template logic.
It means "If the variable cond exists and is not empty, render the following HTML."


if cond=None  || cond="" 
        then it becomes false
else
        true
      

{{ ... }}

Print value inside

Code Example

Script to render page.html using base.html
cat app.py
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.get("/")
def home(request: Request):
    return templates.TemplateResponse(
        request=request,
        name="page.html",
        context={}
    )
          
base.html (template)
cat templates/base.html
<!DOCTYPE html>
<html>
<head>
    <title>
      {% block title %}
        My Website
      {% endblock %}
    </title>
</head>
<body>
    <h2>My Website Header</h2>
    <hr>
      {% block content %}
      {% endblock %}
    <hr>
    <p>© 2026 My Website</p>
</body>
</html>
Page extending the template
cat templates/page.html
{% extends "base.html" %}

{% block title %}
Home Page
{% endblock %}

{% block content %}

Welcome!

Hello from Jinja2.

{% endblock %}

$ uvicorn app:app --reload --port 8089

http://127.0.0.1:8089

My Website Header
Welcome!
Hello from Jinja2.

© 2026 My Website