Question
I would like to use a
JavaScript library in a TWiki topic.
As far as I can see, to link a <script> in the <head> of
the page, I would need to overwrite %TMPL:DEF{"head"}%.
To use the <body onload="...">, I would need to overwrite
%TMPL:DEF{"bodystart"}%.
I read about
TWikiTemplates and I tried to make a file
templates/Web.Topic.tmpl, using "Main" as Web and my
topic as the Topic. It didn't work.
What is the best way to link a
JavaScript library in the
<head> of the page, and to use the <body onload="...">
function?
Environment
--
TWikiGuest - 04 May 2006
Answer
If you don't mind to add the few lines again after an upgrade, the easiest way would be to simply add your script to
templates/twiki.tmpl.
What you have tried (and the link you've given) suggests that you followed the documentation for the previous TWiki version - TWiki.org is still running version 3. Check out the TWiki.TWikiTemplates topic in your own installation, or on twiki.org use
TWikiTemplates as guidance for more "official" ways to customize templates.
--
HaraldJoerg - 04 May 2006
Thanks a lot for your answer.
I searched the support web and found that if you don't want to overwrite templates/twiki.tmpl, you can copy the files
- templates/view.pattern.tmpl
- templates/twiki.pattern.tmpl
to
- templates/view.myskin.tmpl
- templates/twiki.myskin.tmpl
When you use the skin "myskin", then the new
templates are used. A way to choose an other
skin for a certain topic is described at
TemplateOverridePerTopic.
P.S. I used this to include a Google Map in my
Twiki. I will document my results at
http://www.fstab.de/twiki/bin/view/Main/TWikiNotes
--
FabianStaeber - 05 May 2006
When you create a new skin, you can include javascript in TMPL:DEF
templatejavascript. For instance in view.myskin.tmpl:
%TMPL:INCLUDE{"view.pattern"}%
%TMPL:DEF{"templatejavascript"}%
<script type="text/javascript">
//<![CDATA[
addLoadEvent(setfocus);
function setfocus() {
document.loginform.username.focus();
}
//]]>
</script>%TMPL:END%
The
onload script above is an example from
login.pattern.tmpl, and illustrates how to add a function that should be called at page onload.
--
ArthurClemens - 05 May 2006