Tags:
create new tag
, view all tags

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

TWiki version: TWikiRelease04x00x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Linux
Web server: apache
Perl version: 5.8.7
Client OS: windows
Web Browser: iexplorer
Categories: Javascript

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

 
Topic revision: r4 - 2006-05-05 - ArthurClemens
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.