How do you include javascript in a sub template using Genshi?

90 views
Skip to first unread message

.M.

unread,
Sep 22, 2008, 8:57:52 AM9/22/08
to Genshi
I am having great difficulty getting to grips with how Genshi includes
work in Turbogears.

Any javascript references I put in the head of my sub template are not
being rendered, only those in the master template.

Here is my sub template:
http://pastebin.com/m63cc0d2a

and here is my master template:
http://pastebin.com/mda20b9d

Can I get some advice on this?

There doesn't appear to be any Genshi sample documentation which has
CSS or JS in a sub template. I'm assuming this has to be possible but
no luck working out the right syntax.

Thanks
.M.

Erik Bray

unread,
Sep 22, 2008, 9:59:49 AM9/22/08
to gen...@googlegroups.com

The match blocks in your master.html template don't include the
contents of the element being matched.

For example, your match block for <head> *replaces* the <head> element
in the sub-template. To include the contents of the replaced <head>
back into the match results you need to put ${select('*')} in the
match block somewhere. Or ${select('script')} if all you want are the
scripts.

Lin Qing

unread,
Sep 22, 2008, 10:07:14 AM9/22/08
to gen...@googlegroups.com
In the genshi tutorial,
there was a line:
${select('*[local-name()!="title"]')}

it can help you.

the tag in the sub page's head will not be auto get by the master page.
you must add ${select('*[local-name()!="title"]')} to do that.

also,
<title py:replace="''">remixable.tv</title>
in the master page can change to
<title py:with="title = list(select('title/text()'))">${title or 'remixable.tv'}</title>

the meta tag in the sub page seems like useless.

that's it.
--
Regards,

Lin Qing

.M.

unread,
Sep 22, 2008, 9:15:50 PM9/22/08
to Genshi

Thanks for the help.

I also discovered that writing script tags in the form <script />
was causing all kinds of quiet grief which disappeared when I rewrote
as

<script src="${tg.url('/static/javascript/jquery-1.2.6.min.js')}"
type="text/javascript"><!-- --></script>

.M.

On Sep 23, 12:07 am, "Lin Qing" <kind...@gmail.com> wrote:
> In the genshi tutorial,
> there was a line:
>
> ${select('*[local-name()!="title"]')}
>
> it can help you.
>
> the tag in the sub page's head will not be auto get by the master page.
> you must add ${select('*[local-name()!="title"]')} to do that.
>
> also,
> <title <http://december.com/html/4/element/title.html>

Lin Qing

unread,
Sep 22, 2008, 9:28:23 PM9/22/08
to gen...@googlegroups.com
On Tue, Sep 23, 2008 at 9:15 AM, .M. <modf...@gmail.com> wrote:


Thanks for the help.

I also discovered that writing script tags in the form  <script  />
was causing all kinds of quiet grief which disappeared when I rewrote
as

 <script src="${tg.url('/static/javascript/jquery-1.2.6.min.js')}"
type="text/javascript"><!-- --></script>

why not just say:
{{{
<script src="/static/javascript/jquery-1.2.6.min.js" type="text/javascript"></script>
}}}
 



--
Regards,

Lin Qing
Reply all
Reply to author
Forward
0 new messages