[Moin-user] Adding content (script tag) to HTML header from a macro
Paul Moore
p.f.moore at gmail.com
Wed Nov 30 01:34:02 EST 2005
On 11/29/05, Paul Moore <p.f.moore at gmail.com> wrote:
... (Nir suggested including the script code in the body of the HTML, rather
... 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 = getattr(macro.request, 'TEST_n', 0)
n += 1
macro.request.TEST_n = n
return '<b>Number of calls = %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.
More information about the Moin-user
mailing list