I just figured out another way to get this to work, using a CDATA /
Markup hack.

    class TestMakoWidget(Widget):
        engine_name = 'mako'
        template = u"""
            <script type="text/javascript"
              /*<![CDATA[*/
                for (var i=0; i < 1; i++) alert(i);
              /*]]>*/
            </script>
        """

And render it in a Genshi template using:

    ${Markup(tmpl_context.mako_widget)}

Notice how I'm not calling/rendering the widget?  For some reason this
*works*, yet when I call the widget to render it, it does not!

Both methods feel a bit hackish... is there a Right Way to do this?
and is it documented anywhere?

Thanks,

luke

On Aug 20, 3:36 pm, Luke Macken <[email protected]> wrote:
> Hey guys,
>
> So I'm having trouble rendering a Mako widget, containing JavaScript
> code, in a Genshi template.
>
> Here is an example widget.
>
>     class TestMakoWidget(Widget):
>         engine_name = 'mako'
>         template = u"""
>             <script type="text/javascript">
>                 for (var i=0; i < 1; i++) alert(i);
>             </script>
>         """
>
> In the genshi index.html, I would hope to be able to do something like
> this
>
>    ${Markup(tmpl_context.widget())}
>
> However, this renders my '<' characters as '&lt;'.
>
> The only way I was able to get this to work was by doing this in the
> template:
>
>     <?python from genshi import unescape ?>
>     ${Markup(unescape(Markup(tmpl_context.mako_widget())))}
>
> However, this is unintuitive, and ugly.  There's Got To Be A Better
> Way.
> Does anyone have any ideas?  Am I doing something horribly wrong?
>
> Cheers,
>
> luke
>
> (ps, the quickstart with this test code can be found 
> here:http://lmacken.fedorapeople.org/test-tg2-mako.tar.bz2)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to