Yo
so i have a base.html:
<html>
<body>
<div id="header"> ... </div>
{% block main %}{% endblock %}
<div id="footer"> ... </div>
</body>
</html>
and i also have a page that shows user's posts:
{% extends base.html %|
{% block main%}
<h1>welcome to yours posts hangout!</h1>
... snazzy code here that shows all the posts ...
{% endblock%}
now, the problem is, maybe i have another page like this:
{% extends base.html %|
{% block main%}
<h1>look at all posts by all users!</h1>
... snazzy code here that shows all the posts by all the users ...
{% endblock%}
because we all belong to mensa, we can see that the snazzy code i have is being repeated - twice (for tautological fun!)
i don't want to repeat this code - i mean, if it is going to be a major hassle i will, but otherwise i'd like the one page that has the snazzy code defined, and then slip the small changes above and (possibly) below it in.
my understanding of templates is shaky though - i think this is the way to go about doing it, is there a better/standardised way?
snazzy.html:
{% extends base.html %|
{% block aboveSnazzy%}
{% endblock %}
... snazzy code here that shows all the posts by all the users ...
{% block belowSnazzy%}
{% endblock %}
{% endblock%}
and then for each of the different pieces, i can have:
usersArea.html:
{% extends snazzy.html %|
{% block aboveSnazzy%}
<h1>welcome to yours posts hangout!</h1>
{% endblock %}
{% block belowSnazzy%}
<h1>i didn't think this far ahead in the example</h1>
{% endblock %}
{% endblock%}
etc etc for the other pieces too!
ok, so i know i can just send in a parameter with a different header or what have you - let's pretend that the aboveSnazzy stuff is, i don't know, showing some other template i'd like or doing something non-trivial. Is what i've detailed above the "way" to do it?
cheers!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…