Hi EricHolmberg, Thank you very much for the tip.
On Genshi group, kindy offered a similar, but somewhat more concise, solution (http://groups.google.com/group/genshi/msg/c47bca2e4b0fd996), which I adopted as -- """Pylons controller""" WidgetController(BaseController): def index(self, id): c.widget_template = ( '''<?xml version="1.0" encoding="utf-8"?>''' '''<div xmlns="http://www.w3.org/1999/xhtml" ''' '''xmlns:py="http://genshi.edgewall.org/">''' '''${h.url_for(controller='item', action='index', id=c.id)}''' '''</div>''') return render_genshi('master_template') """Genshi master_template.html""" <?xml version="1.0" encoding="utf-8"?> <?python from genshi.template import MarkupTemplate ?> <html xmlns="..." xmlns:py="..."> <head /> <body> <div>${MarkupTemplate(c.widget_template).generate(c=c, h=h)}</div> </body> </html> How about documenting this recipe on the PylonsHQ? Jerry On Oct 8, 1:29 am, EricHolmberg <[EMAIL PROTECTED]> wrote: > > to insert arbitrary literal XML markup fragments. However, I still > > haven't figured > > out a way to _process_ the Genshi sub-template string _from inside > > another > > Genshi template_, i.e., I want the following to come out as '''/ > > widget''' -- > > > ${_some_uber_magic_("h.url_for(controller='widget', action='index', > > id=None)")} > > > when dynamically included in another Genshi template. > > Ah, now that is a good question! I was thinking that you might be > able to use the "recursive='true'" attribute, but I tested it and it > doesn't work. I'm not sure if there is another clever way to do it. > > So off hand, the only thing I can think of is to either recursively > render until the output doesn't change (really nasty for performance) > or do a pre-render of the stuff from the database. See if this code > might help: > > from genshi import XML > from genshi.template import MarkupTemplate > > def get_url(): > return '/widget' > > def PreRender(xml): > # wrap in html tags to make genshi happy > tmpl = """<html xmlns:py="http://genshi.edgewall.org/" > xmlns:xi="http://www.w3.org/2001/XInclude" > py:strip="" > > > %s > </html> > """ % (xml) > return MarkupTemplate(tmpl).generate(get_url=get_url) > > db_string = '<a href="${get_url()}">Widget</a>' > strTemplate = """ > <html xmlns:py="http://genshi.edgewall.org/" > xmlns:xi="http://www.w3.org/2001/XInclude" > > <span py:replace="PreRender(db_string)"/> > </html> > """ > tmpl = MarkupTemplate(strTemplate) > stream = tmpl.generate(db_string=db_string, PreRender=PreRender) > output = stream.render('xhtml') > print output --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
