I use Jinja2, and I'm trying to create a couple of tags that work together, so if I have a template that looks something like this:
{{ my_summary() }}
... arbitrary HTML ...
{{ my_values('Tom', 'Dick', 'Harry') }}
... arbitrary HTML ...
{{ my_values('Fred', 'Barney') }}
As a result, I get the following:
This page includes information about <b>Tom</b>, <b>Dick</b>, <b>Harry</b>, <b>Fred</b>, and <b>Barney</b>.
... arbitrary HTML ...
<h1>Tom, Dick, and Harry</h1>
... arbitrary HTML ...
<h1>Fred and Barney</h1>
In other words, my_summary () at the top of the page contains information presented later on the page. He must be smart enough to take into account the expressions that occur in the include
and operators import
.
What is the best way to do this?
source
share