views:

404

answers:

1

I would like to do:

{% if appnav %}
<hr />
<div id="appnav">
    <ul class="tabs">
        {% block appnav %}{% endblock %}
    </ul>
</div>
{% endif %}

...however, testing for the present use of a block by templates further down the inheritance chain doest seem to work.

Is there some other conditional that might do this?

+2  A: 

The template language doesn't provide exactly what you're looking for. Child templates can call the parent block with {{ block.super }}, but parent templates can't reference child templates.

Your best bet will probably be to write a custom template tag. There are two sections in the template manual to review.

First, Parsing until another block tag. This will give you the basics of how to parse.

Second, Parsing until another block tag and saving contents. By placing a block tag inside the custom tag, you could detect content and wrap it as appropriate. This should work, because I believe the inner block tag will be parsed first. If that doesn't work, subclass the existing block template tag provided by django to implement your special magic.

Jarret Hardie
Thank you... I'll need to do some work and learning to come up with an answer as you've prescribed.Thanks again.
Antonius Common