> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to