On 14 Nov 2005, at 06:06, Tom Tobin wrote:

A bit stumped here . . .  Is there a recommended convention for
repeating blocks within a template?  e.g., I have a paginated
object_list generic view, and I want to repeat my pager code (i.e.,
"back", "next") at both the top and bottom of the list without copying
and pasting.

Not really. You can write a custom template tag for your buttons but that might be considered overkill - and would also mean that some of your presentation logic would end up in Python code (in the template tag definition).

Maybe it's time we bit the bullet and introduced a {% capture %} tag (or similar) that chucks the rendered output of its contents in a variable in the context. Then you could do this:

{% capture pagination_controls %}
... HTML goes here ...
{% end capture %}
{{ pagination_controls }}

... more stuff ...

{{ pagination_controls }}

I think we've avoided this in the past because it makes Django's template language too much like a programming language, but I think it provides an elegant solution to your problem and hence should be a candidate for inclusion - unless we can come up with a more elegant solution.

Cheers,

Simon Willison

Reply via email to