django - Reusable app, define block only if not defined -


my app uses django's messaging middleware.

in base template app have:

{% extends "base.html" %}  {% block messages %} <ul class="messagelist">     {% message in messages %}     <li{% if message.tags %} class="{{ message.tags }}_message"{% endif %}>{{ message|capfirst }}</li>     {% endfor %} </ul> {% endblock messages %} 

the problem override 'messages' block in site-scoped base.html.

so if have styles defined in site base in example:

{% block messages %} {% if messages %}     <ul class="messagelist ui-state-highlight">     {% message in messages %}         <li{% if message.tags %} class="{{ message.tags }}_message"{% endif %}>{{ message|capfirst }}</li>     {% endfor %}     </ul> {% endif %} {% endblock messages %} 

my 'reusable' template remove ui-state-highlight...

any way can define block messages in app's base if not defined?

if follow you're trying - write app provide content block if needed, use parent template's block if available - think should it:

{% extends "base.html" %} {% block messages %}     {% if block.super %}         {{ block.super }}     {% else %}         <ul class="messagelist">         {% message in messages %}             <li{% if message.tags %} class="{{ message.tags }}_message"{% endif %}>{{ message|capfirst }}</li>         {% endfor %}         </ul>     {% endif %} {% endblock %} 

that's untested, though - it's possible block.super works oddly. , won't distinguish between parent template not defining messages block @ , defining empty block.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -