Is it possible to create a django template that can be used (nested) inside of another django template? I know of the extends command, but I don’t think that is what I’m looking for. Maybe I just don’t know how to make it work for this situation. Let me give an example.
It is common in most webapps to display the user’s login status, I’m looking for a way to put the logic for this (with the corresponding “Welcome Mr. Foo” and “Need to sign up?”) into a small template, like this:
loginstatus.html
{% if LoggedIn %}
Message message link link
{% else %}
Other message different link
{% endif %}
Now, I figure I’ll have to call the rendering engine and store this output into a variable, then pass that to the base template when I render it, so that my base template looks like this:
index.html
<html>
<head>
</head>
<body>
<div id="Header">{{ LoginStatus }}</div>
</body>
</html>
Now, I know this is a pretty lame example, it only saved me 5 lines, but I envision doing this for creating a Navigation bar based on the user’s role, displaying a news feed with regard to the users position or selected interest, etc.
So, in short, is it possible (because I haven’t been able to make it work how I envision it) to pre-render a django template and then include that rendered html into another django template?
I don’t think it matters, but I am working with Google App Engine also, if that changes anything.
For that particular example, you can use the
includetag to include a snippet.For the nav bar and news feed, custom template tags – specifically, inclusion tags – would be more appropriate.