-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
menus empty if generate_menu not called within same block. #79
Comments
I know a bit more now. See in an example here with a base.html: {% load menu %}
<html>
<head></head>
<body>
{% block menu_wrapper %}
{% generate_menu %}
{% endblock %}
{% block body %}{% endblock %}
</body>
</html> ...and here a template that extends it: {% extends 'base.html' %}
{% load menu %}
{% block body %}
{{ menus }} <!-- do something with the menus here -->
{% endblock %} This does not work, as stated earlier. BUT, if you put the block containing the {% load menu %}
<html>
<head></head>
<body>
{% block menu_wrapper %}
{% generate_menu %}
{% block body %}{% endblock %}
{% endblock %}
</body>
</html> You might ask, why the heck do you need a separate block for I ditched django_hosts later, but the separate block remained in my base html - so the bug stayed with me. I think I could live with seeing this as not a bug, but a "certain behaviour". But it should be stated in the docs as the sentence there is a bit misleading: Note that I would change that. it's even not good practice, as suggested there, to run generate_menu within a sub template. It is sufficient to run once, in the base (most root) template: BUT, it must be within a block, that's true. So the only way I can think of is like in my second example above: to put a |
AAARGH. Sorry for the spam. It's much easier... {% load menu %}
<html>
<head></head>
<body>
{% generate_menu %}
{% block body %}{% endblock %}
</body>
</html> I was blinded by the docs because they say it has to be within a block. It hasn't in fact. Or only, if using in a sub template that extends another. So: best practice is: put it into the main, root template, just anywhere. No block needed. Exactly said, DON'T put it in a block in your root template, as this will most certainly be overridden. |
Incredible! I didn't know this, either! Thank you a lot!
I will make sure to update the docs |
the docs say that
{% generate_menu %}
needs to be called within a block. I think this is not correct, as it seems to need to be called within the same block you are using the menu.Using a simple pattern to demonstrate this:
Now use a template that inherits this:
Here you just override the
content
block. Thegenerate_menu
block should be inherited byextend
and be untouched, sogenerate_menu
should be called - which I can confirm by debugging.The problem seems to be that the context which is passed to
MenuNode.render()
does't seem to get passed through to the correct template in application.html.If I add
{% generate_menu %}
within thecontent
block inapplication.html
, everything is ok. Even if I add{% generate_menu %}
in a newgenerate_menu
block inapplication.html
(which is "a block", like the docs say), it does NOT work.Is this intended behaviour? Or a bug?
The text was updated successfully, but these errors were encountered: