On 11/29/05, Paul Moore <p.f.moore@...> wrote:
... (Nir suggested including the script code in the body of the HTML, rathe=
r
... than the header)
> Hmm, I guess that would work with one of the examples I'm using
> (although I guess I'll have to get a bit clever to ensure that if I
> use the macro twice, I won't include the script twice).
In order to check if this is the first time the macro has been called
on this page, I can add attributes to the request object - example:
def execute(macro, args):
n =3D getattr(macro.request, 'TEST_n', 0)
n +=3D 1
macro.request.TEST_n =3D n
return '<b>Number of calls =3D %s</b>' % (n,)
This seems to work OK - but is it acceptable practice? If not, is
there any other way of telling (on a per-render basis) how many times
the macro has been called so far on this page?
(I've not found any formal documentation on how to write a macro, what
APIs are supported, etc. I'm going on experimentation and picking
ideas up from other people's code. Is that the best way, or have I
missed some docs I should be referring to?)
Paul.
|