djc / askama

Type-safe, compiled Jinja-like templates for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why if block does not work inside another block

HosMercury opened this issue · comments

I have this code :

<div id="content d-flex justify-content-center align-items-center">
    {% block content %}

    {# flash messages #}
    {% if let Some(message) = message %}
    <span class="bg-danger text-white d-flex justify-content-center container-fluid">
      <strong class="">{{ message }}</strong>
    </span>
    {% endif %}

    {% endblock %}
  </div>
  

The part commented flash messages does not show inside the block unless I moved it outside the bloc like this :

<div id="content d-flex justify-content-center align-items-center">
    {# flash messages #}
    {% if let Some(message) = message %}
    <span class="bg-danger text-white d-flex justify-content-center container-fluid">
      <strong class="">{{ message }}</strong>
    </span>
    {% endif %}

    {% block content %}

    {% endblock %}
  </div>

what If wanted it like the first example code inside the block ?

Is this at the top level of your template? Where is the message value coming from?

yes it is the base templ

Is this at the top level of your template? Where is the message value coming from?

yes

This probably has something to do with the inheritance setup, but it's hard to say for sure without more context (like your type definitions -- ideally, a full reproducible example).