You have to make a new formatter, not use the one passed to you (since that one has a context scoped to the original page). You could try just replacing formatter.context and then putting it back after your render call.

--Noah

On Mar 27, 2010, at 12:10 PM, En_t_end wrote:

Hello,
I have the following:

class MyMacro(WikiMacroBase):

   def expand_macro(self, formatter, name, args):
       return WikiPage(self.env, formatter.context.resource).name


[[MyMacro]] correct return page name. But if I load page in other
Macro from another page by call WikiPage(..., page) which include this
[[MyMacro]], this return unexpexted result.

For example:

class AnotherMacro(WikiMacroBase):

   def wiki_output(self, formatter, content):
       out = StringIO()
       Formatter(self.env, formatter.context).format(content, out)
       return Markup(out.getvalue())

   def expand_macro(self, formatter, name, args):
       page = WikiPage(self.env, pagewhichincludemymacro)
       return wiki_output(formatter, page.text)

I want to retrieve page name where MyMacro located really at
MyMacro.expand_macro . Thanks

--
You received this message because you are subscribed to the Google Groups "Trac Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en .


--
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to