none
[openafs-wiki.git] / TWiki / TWikiSkins.mdwn
1 <div>
2   <ul>
3     <li><a href="#TWiki Skins"> TWiki Skins</a><ul>
4         <li><a href="#Overview"> Overview</a></li>
5         <li><a href="#Defining Skins"> Defining Skins</a></li>
6         <li><a href="#Variables in Skins"> Variables in Skins</a><ul>
7             <li><a href="#The "Go" Box and Navigation Box"> The "Go" Box and Navigation Box</a></li>
8           </ul>
9         </li>
10         <li><a href="#Using Cascading Style Sheets"> Using Cascading Style Sheets</a></li>
11         <li><a href="#Attachment Tables"> Attachment Tables</a></li>
12         <li><a href="#Packaging and Publishing Skins"> Packaging and Publishing Skins</a></li>
13         <li><a href="#Browsing Installed Skins"> Browsing Installed Skins</a></li>
14         <li><a href="#Activating Skins"> Activating Skins</a></li>
15       </ul>
16     </li>
17   </ul>
18 </div>
19
20 # <a name="TWiki Skins"></a> TWiki Skins
21
22 _Skins overlay regular templates with alternate header/footer layouts; topic text is not affected_
23
24 ## <a name="Overview"></a> Overview
25
26 Skins are customized [[TWikiTemplates]] files. You can use skins to change the look of a %WIKITOOLNAME% topic, for example, the layout of the header and footer. Rendered text between header and footer does **_not_** change. You can also use skins to define an alternate view, like a view optimized for printing.
27
28 ## <a name="Defining Skins"></a> Defining Skins
29
30 Skin files are located in the `twiki/templates` directory and are named with the syntax: <code>**&lt;scriptname&gt;.&lt;skin&gt;.tmpl**</code>. For example, the **Printable** skin for the `view` template is `view.print.tmpl`.
31
32 Use the existing [[TWikiTemplates]] (like `view.tmpl`) or skin files as a base for your own skin, name it for example `view.myskin.tmpl`.
33
34 ## <a name="Variables in Skins"></a> Variables in Skins
35
36 You can use [[template variables|Main/TWikiTemplates#TemplateVariables]], [[TWikiVariables]], and other predefined variables to compose your skins. Some commonly used variables in skins:
37
38 <table border="1" cellpadding="0" cellspacing="0">
39   <tr>
40     <th bgcolor="#99CCCC"><strong> Variable: </strong></th>
41     <th bgcolor="#99CCCC"><strong> Expanded to: </strong></th>
42   </tr>
43   <tr>
44     <td><code>%WIKILOGOURL%</code></td>
45     <td> Link of page logo </td>
46   </tr>
47   <tr>
48     <td><code>%WIKILOGOIMG%</code></td>
49     <td> Image URL of page logo </td>
50   </tr>
51   <tr>
52     <td><code>%WIKILOGOALT%</code></td>
53     <td> Alt text of page logo </td>
54   </tr>
55   <tr>
56     <td><code>%WEBBGCOLOR%</code></td>
57     <td> Web specific background color, defined in the [[Main/WebPreferences]]</td>
58   </tr>
59   <tr>
60     <td><code>%WIKITOOLNAME%</code></td>
61     <td> The name of your TWiki site </td>
62   </tr>
63   <tr>
64     <td><code>%SCRIPTURL%</code></td>
65     <td> The script URL of TWiki </td>
66   </tr>
67   <tr>
68     <td><code>%SCRIPTSUFFIX%</code></td>
69     <td> The script suffix, ex: <code>.pl</code>, <code>.cgi</code></td>
70   </tr>
71   <tr>
72     <td><code>%WEB%</code></td>
73     <td> The name of the current web. <strong><em>Note:</em></strong> It is recommended to URL-encode the variable in form actions with <code>%INTURLENCODE{"%WEB%"}%</code> for proper handling in an internationalized environment </td>
74   </tr>
75   <tr>
76     <td><code>%TOPIC%</code></td>
77     <td> The name of the current topic. <strong><em>Note:</em></strong> It is recommended to URL-encode the variable in form actions with <code>%INTURLENCODE{"%TOPIC%"}%</code> for proper handling in an internationalized environment </td>
78   </tr>
79   <tr>
80     <td><code>%WEBTOPICLIST%</code></td>
81     <td> Common links of current web, defined in the [[Main/WebPreferences]]. It includes a [[Main/WebHome#GoBox]]</td>
82   </tr>
83   <tr>
84     <td><code>%TEXT%</code></td>
85     <td> The topic text, e.g. the content that can be edited </td>
86   </tr>
87   <tr>
88     <td><code>%META{"form"}%</code></td>
89     <td>[[Main/TWikiForms]], if any </td>
90   </tr>
91   <tr>
92     <td><code>%META{"attachments"}%</code></td>
93     <td>[[Main/FileAttachment]] table </td>
94   </tr>
95   <tr>
96     <td><code>%META{"parent"}%</code></td>
97     <td> The topic parent </td>
98   </tr>
99   <tr>
100     <td><code>%EDITTOPIC%</code></td>
101     <td> Edit link </td>
102   </tr>
103   <tr>
104     <td><code>%REVTITLE%</code></td>
105     <td> The revision title, if any, ex: <code>(r1.6)</code></td>
106   </tr>
107   <tr>
108     <td><code>%REVINFO%</code></td>
109     <td> Revision info, ex: <code>r1.6 - 24 Dec 2002 - 08:12 GMT - Main.admin</code></td>
110   </tr>
111   <tr>
112     <td><code>%WEBCOPYRIGHT%</code></td>
113     <td> Copyright notice, defined in the [[Main/WebPreferences]]</td>
114   </tr>
115   <tr>
116     <td><code>%BROADCASTMESSAGE%</code></td>
117     <td> Broadcast message at the beginning of your view template, can be used to alert users of scheduled downtimes; is set in [[Main/TWikiPreferences]]</td>
118   </tr>
119 </table>
120
121 <a name="GoBox"></a>
122
123 ### <a name="The &quot;Go&quot; Box and Navigation Box"></a> The "Go" Box and Navigation Box
124
125 The `%WEBTOPICLIST%` includes a "Go" box to jump to a topic. The box also understand URLs, e.g. you can type <http://www.google.com/> to jump to an external web site. The feature is handy if you build a skin that has a select box of frequently used links, like Intranet home, employee database, sales database and such. A little JavaScript gets into action on the onSelect method of the select tag to fill the selected URL into the "Go" box field, then submits the form.
126
127 Here is an example form that has a select box and the "Go" box for illustration purposes. You need to have JavaScript enabled for this to work:
128
129 <form action="http://www.dementia.org/twiki//view/%WEB%/%TOPIC%" name="sample">
130   <table border="3">
131     <tr>
132       <td><select name="sel" onchange="this.form.topic.value=this.options[this.selectedIndex].value; this.form.submit()"><option selected value="">Navigate...</option>
133           <option value="http://www.twiki.org/">Intranet home</option>
134           <option value="Main.TWikiUsers">Employee index</option>
135           <option value="Main.WebHome">Main web</option>
136           <option value="TWiki.WebHome">TWiki web</option>
137           <option value="http://www.google.com/">Google</option>
138           <option value="http://www.yahoo.com/">Yahoo!</option></select> Bare bones header for demo only </td>
139     </tr>
140     <tr>
141       <td> %WEBTOPICLIST% </td>
142     </tr>
143   </table>
144 </form>
145
146 ## <a name="Using Cascading Style Sheets"></a> Using Cascading Style Sheets
147
148 Although work is underway at TWiki:Codev.CssClassNames, the regular templates files currently do not use style sheets. Many skin developers, however, choose to use them; it helps in separating style from content.
149
150 Example: To use a style sheet for the broadcast message, add this to `view.myskin.tmpl`:
151
152     <style type="text/css">
153     .broadcastmessage {
154         background: yellow; display:block;
155         border-style:solid;border-width: 2px;border-color:red;
156     }
157     .broadcastmessage strong {color: red}
158     </style>
159
160 Then add a div tag to the `%BROADCASTMESSAGE%` variable located after the `#PageTop` anchor or after the opening form tag:
161
162     <div class="broadcastmessage"> %BROADCASTMESSAGE% </div>
163
164 ## <a name="Attachment Tables"></a> Attachment Tables
165
166 Controlling the look and feel of attachment tables is a little bit more complex than for the rest of a skin. By default the attachment table is a standard TWiki table, and the look is controlled in the same ay as other tables. In a very few cases you may want to change the _content_ of the table as well.
167
168 The format of standard attachment tables is defined through the use of special _TWiki template macros_ which by default are defined in the `templates/twiki.tmpl` template using the `%TMPL:DEF` macro syntax described in [[TWikiTemplates]]. These macros are:
169
170 <table border="1" cellpadding="0" cellspacing="0">
171   <tr>
172     <th bgcolor="#99CCCC"><strong> Macro </strong></th>
173     <th bgcolor="#99CCCC"><strong> Description </strong></th>
174   </tr>
175   <tr>
176     <td><code>ATTACH:files:header</code></td>
177     <td> Standard title bar </td>
178   </tr>
179   <tr>
180     <td><code>ATTACH:files:row</code></td>
181     <td> Standard row </td>
182   </tr>
183   <tr>
184     <td><code>ATTACH:files:footer</code></td>
185     <td> Footer for all screens </td>
186   </tr>
187   <tr>
188     <td><code>ATTACH:files:header:A</code></td>
189     <td> Title bar for upload screens, with attributes column </td>
190   </tr>
191   <tr>
192     <td><code>ATTACH:files:row:A</code></td>
193     <td> Row for upload screen </td>
194   </tr>
195   <tr>
196     <td><code>ATTACH:files:footer:A</code></td>
197     <td> Footer for all screens </td>
198   </tr>
199 </table>
200
201 The format of tables of file versions in the Upload screen are also formattable, using the macros:
202
203 <table border="1" cellpadding="0" cellspacing="0">
204   <tr>
205     <th bgcolor="#99CCCC"><strong> Macro </strong></th>
206     <th bgcolor="#99CCCC"><strong> Description </strong></th>
207   </tr>
208   <tr>
209     <td><code>ATTACH:versions:header</code></td>
210     <td> Header for versions table on upload screen </td>
211   </tr>
212   <tr>
213     <td><code>ATTACH:versions:row</code></td>
214     <td> Row format for versions table on upload screen </td>
215   </tr>
216   <tr>
217     <td><code>ATTACH:versions:footer</code></td>
218     <td> Footer for versions table on upload screen </td>
219   </tr>
220 </table>
221
222 The `ATTACH:row` macros are expanded for each file in the attachment table, using the following special tags:
223
224 <table border="1" cellpadding="0" cellspacing="0">
225   <tr>
226     <th bgcolor="#99CCCC"><strong> Tag </strong></th>
227     <th bgcolor="#99CCCC"><strong> Description </strong></th>
228   </tr>
229   <tr>
230     <td><code>%A_URL%</code></td>
231     <td> URL that will recover the file </td>
232   </tr>
233   <tr>
234     <td><code>%A_REV%</code></td>
235     <td> Revision of this file e.g. "1.1" </td>
236   </tr>
237   <tr>
238     <td><code>%A_ICON%</code></td>
239     <td> A file icon suitable for representing the attachment content </td>
240   </tr>
241   <tr>
242     <td><code>%A_FILE%</code></td>
243     <td> The name of the file </td>
244   </tr>
245   <tr>
246     <td><code>%A_SIZE%</code></td>
247     <td> The size of the file </td>
248   </tr>
249   <tr>
250     <td><code>%A_DATE%</code></td>
251     <td> The date the file was uploaded </td>
252   </tr>
253   <tr>
254     <td><code>%A_USER%</code></td>
255     <td> The user who uploaded it </td>
256   </tr>
257   <tr>
258     <td><code>%A_COMMENT%</code></td>
259     <td> The comment they put in when uploading it </td>
260   </tr>
261   <tr>
262     <td><code>%A_ATTRS%</code></td>
263     <td> The attributes of the file as seen on the upload screen e.g "h" for a hidden file </td>
264   </tr>
265 </table>
266
267 Note: it is easy to change the look and feel for an entire site by editing the `twiki.tmpl` template file. However, to simplify upgrading, you should avoid doing this. Instead, write a skin-specific template file e.g. `attach.myskin.tmpl` and use `%TMPL:INCLUDE{attach.myskin.tmpl}%` to include it in each of your skin files. As long as it it included _after_ twiki.tmpl, your macro definitions will override the defaults defined there.
268
269 ## <a name="Packaging and Publishing Skins"></a> Packaging and Publishing Skins
270
271 See TWiki:Plugins/SkinPackagingHowTo and TWiki:Plugins/SkinDeveloperFAQ
272
273 ## <a name="Browsing Installed Skins"></a> Browsing Installed Skins
274
275 You can try all installed skins in [[TWikiSkinBrowser]].
276
277 ## <a name="Activating Skins"></a> Activating Skins
278
279 A skin can be activated in two ways:
280
281 - Define the `SKIN` Preference variable in [[TWikiPreferences]], one of the [[WebPreferences]], or in a user - Main.admin - topic.
282   - `Set SKIN = print`
283
284 - Add `?skin=name` to the URL, for this example:
285   - <http://www.dementia.org/twiki//view/%WEB%/%TOPIC%?skin=print> (for the print view skin)
286   - <http://www.dementia.org/twiki//view/%WEB%/%TOPIC%?skin=plain> (for the plain view skin that has no header and footer)
287
288 The <code>**?skin=name**</code> URL parameter overrides the SKIN Preference value.
289
290 -- TWiki:Main.PeterThoeny - 25 Jul 2004 %BR% -- TWiki:Main.CrawfordCurrie - 30 Jun 2004 %BR%