Wiki source code of Skins

Version 17.6 by Sorin Burjan on 2011/04/13

Hide last authors
MariusButuc 11.1 1 (% class="floatinginfobox" %)
2 (((
Raluca Stavro 1.1 3 **Contents**
4
5 {{toc depth="3" start="2"/}}
6 )))
7
MariusButuc 11.1 8 = XWiki Skins =
9
hennejg 11.2 10 == How to create a new Skin ==
Sorin Burjan 13.3 11
Sorin Burjan 13.4 12 {{warning}}
13 To create a new Skin, you must have access to the server side of the XWiki Enterprise instance.
14 {{/warning}}
Sorin Burjan 13.3 15
Sorin Burjan 13.5 16 To create a new Skin, you have to create a new direcory inside the webapps/xwiki/skins folder and then add Velocity templates,CSS stylesheets, Javascript files and images inside it. For example, if you want to remove the logo from the header of the pages, follow these steps:
MariusButuc 11.1 17
Sorin Burjan 13.5 18 1. Inside the webapps/xwiki/skins folder, create a folder named myskin. Copy all files from webapps/xwiki/skins/colibri folder into your new skin directory.
19 1. Change the Skin at global or instance level and set it as myskin ( see [[this>>AdminGuide.Skins]] page for more informations about how to change the Skin )
Sorin Burjan 13.6 20 1. Open any page in view mode and you will notice that myskin layout is the same as the colibri layout (if the skin changes to albatross means that your theme wasn't used. Check the names of your skin directory. Note that skin names are case-sensitive)
Sorin Burjan 13.5 21 1. Change the global template:
22 1*. to remove the logo, modify the global.vm template under the new Skin and delete the line:(((
23 {{code language="html"}}
24 <img src="$!logourl" alt="Wiki Logo"/>
MariusButuc 11.1 25 {{/code}}
26 )))
Sorin Burjan 13.5 27 1. Save the template
Raluca Stavro 1.1 28
Sorin Burjan 13.5 29 Open any page in view mode and you will notice that the XWiki logo is not displayed anymore. Congratulations! You have created a new minimal XWiki Skin.
Sorin Burjan 13.4 30
hennejg 11.2 31 == How to override a Skin ==
Sorin Burjan 13.3 32
Sorin Burjan 13.4 33 {{warning}}
34 To change the Skin, the user must have administrating rights. In the case that you have these rights, make sure that you switch to the Advanced mode in your profile, to enable the advanced options on the top main menu.
35 {{/warning}}
Sorin Burjan 13.3 36
Raluca Stavro 1.1 37 An alternative for creating a new Skin is the possibility to override an existing Skin. The advantage of overriding an existing Skin is the fact that you don't need access to the server filesystem in order to modify the files used by the current Skin.
38 To override a Skin, you have to use the same document that is used to store the Skin.
hennejg 11.2 39 {{id name="5a"/}}
Sorin Burjan 13.4 40
hennejg 11.2 41 === A. Creating a Skin document ===
Sorin Burjan 13.3 42
Sorin Burjan 13.4 43 {{warning}}
Sorin Burjan 14.3 44 You need to have the **advanced edit mode** activated to access the object editor. Please refer to [[platform:Features.PageEditing]] for more information.
Sorin Burjan 13.4 45 {{/warning}}
Sorin Burjan 13.3 46
Raluca Stavro 1.1 47 To create a new Skin document, follow these steps:
48
Sorin Burjan 14.3 49 1. Create a new page. Name it MySkinPage(((
Sorin Burjan 14.4 50 [[image:createSkinPage.png||style="border:1px solid black; width:650px"]]
MariusButuc 11.1 51 )))
Sorin Burjan 14.2 52 1. Edit the document's objects (Edit -> Objects)
53 1. Add an object of type XWiki.XWikiSkins to the document
54 1. Click on add
Sorin Burjan 14.3 55 1. Set the base skin property to colibri. Now, you use colibri as a base skin. As you can see, no files were copied on the file system, but your skin uses colibri.(((
Sorin Burjan 16.2 56 [[image:addSkinObject.png||style="border:1px solid black; width:650px"]]
Sorin Burjan 14.3 57 )))
Sorin Burjan 14.2 58 1. Save the document
MariusButuc 11.1 59
Sorin Burjan 17.2 60 === B. Working with the XWiki.XWikiSkins class ===
Sorin Burjan 13.4 61
Sorin Burjan 17.2 62 The base element in overriding a Skin is the XWiki.XWikiSkins class ( http://localhost:8080/xwiki/bin/view/XWiki/XWikiSkins ). In order to modify the templates or the files used by a Skin, you have to work with the properties of this class. By default, the Skin class contains a set of properties that allows you to override some of the templates and files used by the Skin, and it also allows you to set the name of the logo displayed in the header of the interface.
63 To override other templates or files, you have to add new properties to the Skin class. For example, if you want to override myfile.vm ( or myfile.css, or myfile.js ), follow these steps:
MariusButuc 11.1 64
Sorin Burjan 17.2 65
66 1. Go to the XWiki.XWikiSkins document
67 1. Edit the document's class (Edit -> Class) or follow this link: http://localhost:8080/xwiki/bin/edit/XWiki/XWikiSkins?editor=class
68 1. Add a new property myfile.vm as TextArea type
Sorin Burjan 17.4 69 1. Click on Add. The myfile.vm property should appear in the list(((
Sorin Burjan 17.2 70 [[image:editXWikiSkins.png||style="border:1px solid black; width:650px"]]
MariusButuc 11.1 71 )))
Sorin Burjan 17.2 72 1. Save the document
Raluca Stavro 1.1 73
hennejg 11.2 74 === C. Using a Skin document ===
Sorin Burjan 13.4 75
Raluca Stavro 1.1 76 To use a Skin document, follow these steps:
MariusButuc 11.1 77
Sorin Burjan 17.5 78 1. Go to the (% class="sectionblockcodecolored" %)Skin(%%) property from inside the (% class="sectionblockcodecolored" %)Administration(%%) page, Presentation section
79 1. Set the value of the files as being the full name of the Skin document. For our skin page created above, we will type Main.MySkinPage
80 1. Save the preferences
Sorin Burjan 13.4 81
hennejg 11.2 82 === D. Overriding the Skin components ===
Sorin Burjan 13.4 83
Sorin Burjan 17.6 84 Let's add a "HELLO," before the username on the top right menu, not by modifying the (% class="sectionblockcodecolored" %)menuview.vm(%%) template on the server, but overriding it inside the Skin document. Follow these steps:
MariusButuc 11.1 85
Raluca Stavro 12.1 86 ==== Method 1: By editing the XWiki.XWikiSkins properties on the Skin document ====
87
Sorin Burjan 17.6 88 |(% style="width: 60%; overflow-x: auto; " %)(((
89 1. Add a (% class="sectionblockcodecolored" %)TextArea(%%) property named (% class="sectionblockcodecolored" %)menuview.vm(%%) to the (% class="sectionblockcodecolored" %)XWiki.XWikiSkins(%%) class
90 1. Edit your skin document's objects (Edit -> Objects) and open the properties of the (% class="sectionblockcodecolored" %)XWiki.XWikiSkins(%%) object
91 1. Copy the original content of the menuview.vm template and paste it in the property field named menuview.vm. If you don't have access to the server filesystem, open the template by following one of these links:if the previous link is not valid, go to http://localhost:8080/xwiki/templates/global/vmmenuview.vm
92 1. (((
93 Replace the following code:(% style="color:#222222;" %){{code language="xml"}}
MariusButuc 11.1 94 <a class="glink"
Raluca Stavro 1.1 95 href="$!xwiki.getURL($context.user, 'view')"
96 id="headeruser">
97 $!xwiki.getUserName($context.user, false)
MariusButuc 11.1 98 </a>
Sorin Burjan 17.6 99 {{/code}}(%%)
100 )))(((
101 with(% style="color:#222222;" %){{code language="xml"}}
MariusButuc 11.1 102 <a class="glink"
Raluca Stavro 1.1 103 href="$!xwiki.getURL($context.user, 'view')"
104 id="headeruser">
105 HELLO,
106 $!xwiki.getUserName($context.user, false)
MariusButuc 11.1 107 </a>
Sorin Burjan 17.6 108 {{/code}}(%%)
MariusButuc 11.1 109 )))
Sorin Burjan 17.6 110 1. Save the document
MariusButuc 11.1 111 )))|(((
Sorin Burjan 13.4 112 [[[[image:6.png||style="border: 3px solid rgb(221, 221, 221);" width="100%"]]>>attach:6.png]]
MariusButuc 11.1 113 )))
Raluca Stavro 1.1 114
Raluca Stavro 12.1 115 ==== Method 2: By attaching files to the current Skin document ====
Sorin Burjan 13.4 116
117 1. create a copy of the global.vm template; if you don't have access to the server filesystem, open the template by following one of these links:
Raluca Stavro 12.1 118 1*. http://localhost:8080/xwiki/skins/mybaseskin/global.vm ( where mybaseskin is the current Skin used in the Skin document ), or
119 1*. if the previous link is not valid, go to http://localhost:8080/xwiki/templates/global.vm
120 1. replace the following code inside the copy of global.vm template:(((
121 {{code language="xml"}}
122 <a class="glink"
123 href="$!xwiki.getURL($context.user, 'view')"
124 id="headeruser">
125 $!xwiki.getUserName($context.user, false)
126 </a>
127 {{/code}}
128 )))with(((
129 {{code language="xml"}}
130 <a class="glink"
131 href="$!xwiki.getURL($context.user, 'view')"
132 id="headeruser">
133 HELLO,
134 $!xwiki.getUserName($context.user, false)
135 </a>
136 {{/code}}
137 )))
138 1. attach the copy of global.vm template to the current Skin document page
139
Raluca Stavro 1.1 140 Now, open any document in view mode and you will notice the nice "HELLO," before your username.
MariusButuc 11.1 141 Follow the same process in order to override (% class="sectionblockcodecolored" %)Javascript(%%) and (% class="sectionblockcodecolored" %){{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}}(%%) files ( http://localhost:8080/xwiki/skins/colibri/myfile.css ).
Raluca Stavro 1.1 142
Marta Girdea 13.1 143 ==== 3. Overriding a skin resource ====
144
145 Just like templates, resource files such as images or css/js files can be overridden. To do that, the replacement must be attached to the Skin document, making sure it complies with the naming convention explained below. To find out the right name for your replacement resource, here is the trick:
Sorin Burjan 13.4 146
Marta Girdea 13.1 147 1. find the path on the filesystem of the resource to replace (you can easily obtain that information using development tools such as [[Firebug>>http://getfirebug.com/]]); for instance, let's say this path is either
Sorin Burjan 13.4 148 {{code}}/xwiki/resources/icons/silk/myicon.gif{{/code}}
Marta Girdea 13.1 149 for a resource found in the general resource directry, or
Sorin Burjan 13.4 150 {{code}}/xwiki/skins/colibri/myimage.png{{/code}}
Marta Girdea 13.1 151 if the resource is specific to a certain skin, in this case 'colibri'.
152 1. strip from this path everything from the beginning until 'resources/' or the name of the skin, included; in the previous examples, you will obtain in the first case
Sorin Burjan 13.4 153 {{code}}icons/silk/myicon.gif{{/code}}
Marta Girdea 13.1 154 and in the second case simply
Sorin Burjan 13.4 155 {{code}}myimage.png{{/code}}
Marta Girdea 13.1 156 1. in this path, replace '/' with '.'; after this operation, we will get {{code}}icons.silk.myicon.gif{{/code}} for the first image example, while the second one remains unchanged. **This is the name of the file corresponding to the resource that you need to attach to the Skin document in order to make the replacement**.
157 1. create a file named as explained above and attach it to your Skin
158
159 {{info}}
160 **Technical note**: This trick works for any resource whose URL is generated in the skin by the {{code}}$xwiki.getSkinFile(){{/code}}, {{code}}$xwiki.jsfx(){{/code}} or {{code}}$xwiki.ssfx(){{/code}} methods, for instance like this:
161
162 {{code language="none"}}
163 .infomessage {
164 background-image: url("$xwiki.getSkinFile('icons/silk/information.gif')");
165 }
166 {{/code}}
167
168 In this case, {{code}}$xwiki.getSkinFile('icons/silk/information.gif'){{/code}} will first search for an image called 'icons.silk.information.gif' attached to the configured Skin document, if any. If that image exists, it will generate its URL. Otherwise, it will continue to search for 'icons/silk/information.gif' in the base skins and finally in the general 'resources/' directory.
169 {{/info}}
170
Sorin Burjan 13.5 171 {{id name="5e"/}}
Sorin Burjan 13.4 172
Sorin Burjan 17.4 173
hennejg 11.2 174 === E. Adding new components to the Skin ===
Sorin Burjan 13.4 175
MariusButuc 11.1 176 If you want to add new files to the skin, like (% class="sectionblockcodecolored" %){{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} (%%) or (% class="sectionblockcodecolored" %)Javascript(%%) files, you have two options:
Raluca Stavro 1.1 177
MariusButuc 11.1 178 * attach the files to the Skin document and reffer them by their URL, or
179 * add new properties to the (% class="sectionblockcodecolored" %)XWiki.XWikiSkins(%%) object from inside the Skin document, and refer them by their name
180
181 For example, if you want to add a new {{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} file to the Skin, named (% class="sectionblockcodecolored" %)mynewfile.css(%%), follow one of these set of steps:
182
Sorin Burjan 13.4 183 |(% style="width: 60%; color: rgb(34, 34, 34);" %)(((
MariusButuc 11.1 184 1. attach the {{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} file to the Skin document
185 1. override the stylesheets.vm template ( check the section [[D>>#5d]] to learn how to override a Skin component ), and add the reference to your file in the template:(((
186 {{code language="xml"}}
187 <link rel="stylesheet"
Raluca Stavro 1.1 188 type="text/css"
189 href="$xwiki.getSkinFile('mynewfile.css')"
MariusButuc 11.1 190 />
191 {{/code}}
192 )))
193 1. save the document
194 )))|(((
Sorin Burjan 13.4 195 [[[[image:7.png||style="border: 3px solid rgb(221, 221, 221);" width="100%"]]>>attach:7.png]]
MariusButuc 11.1 196 )))
Raluca Stavro 1.1 197
198 OR
199
Sorin Burjan 13.4 200 |(% style="width: 60%; color: rgb(34, 34, 34);" %)(((
MariusButuc 11.1 201 1. add a new property to the (% class="sectionblockcodecolored" %)XWiki.XWikiSkins(%%), name it (% class="sectionblockcodecolored" %)mynewfile.css(%%) ( check the section [[B>>#5b]] for more information about how to work with this class ), edit the Skin document's objects ( use the top-left menu: (% class="sectionblockcodecolored" %)EDIT -> OBJECTS(%%) ), and paste the {{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} code into the (% class="sectionblockcodecolored" %)mynewfile.css(%%) field
202 1. override the (% class="sectionblockcodecolored" %)style.css(%%) component ( see the section [[D>>#5d]] for more information about how to override a Skin compoment ) and add the following line to the content of the (% class="sectionblockcodecolored" %)style.css(%%) property:(((
203 {{code language="css"}}
204 @import "mynewfile.css";
205 {{/code}}
206 )))the important thing is to add a reference to the new component from a existing one; you must know most of the components content, so that you will take the best decision about which existing component will contain a reference to the new one
207 1. save the document
208 )))|(((
Sorin Burjan 13.4 209 [[[[image:8.png||style="border: 3px solid rgb(221, 221, 221);" width="100%"]]>>attach:8.png]]
MariusButuc 11.1 210 )))
211
Raluca Stavro 1.1 212 Open any document in view mode and you will notice that the stylesheet is now applied.
213
hennejg 11.2 214 {{id name="5f"/}}
Sorin Burjan 13.4 215
hennejg 11.2 216 === F. Using (% class="sectionblockcodecolored" %)images(%%) in a Skin document ===
Sorin Burjan 13.4 217
hennejg 11.2 218 {{id name="5f1"/}}
Sorin Burjan 13.4 219
hennejg 11.2 220 ==== 1. Changing the (% class="sectionblockcodecolored" %)logo(%%) ====
Sorin Burjan 13.4 221
MariusButuc 11.1 222 For example, if you want to add an image named (% class="sectionblockcodecolored" %)myimage.jpg(%%) as being the logo for the current Skin, follow these steps:
Raluca Stavro 1.1 223
MariusButuc 11.1 224 1. attach the image to the Skin document
225 1. edit the document's objects ( use the top-left menu: (% class="sectionblockcodecolored" %)EDIT -> OBJECTS(%%) )
226 1. use the (% class="sectionblockcodecolored" %)XWiki.XWikiSkins(%%) object and set the (% class="sectionblockcodecolored" %)Logo(%%) property as being the name of the attached image: (% class="sectionblockcodecolored" %)myimage.jpg
227 1. save the document
228
Raluca Stavro 1.1 229 Open any page in view mode and you will notice that the logo is now changed.
230
Sorin Burjan 17.5 231 {{id name="5f2"/}}
MariusButuc 11.1 232
233 ==== 2. Adding images to the Skin interface ====
234
235 To add images to the interface, attach them to the Skin document and use them in the {{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} code. For example, if you want to use (% class="sectionblockcodecolored" %)myimage.jpg(%%) as background image for the pages inside your XWiki Enterprise instance, follow these steps:
236
237 1. attach the image to the Skin document
Sorin Burjan 13.4 238 1. choose one of these actions:
MariusButuc 11.1 239 1*. add a new {{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} component to the Skin, name it (% class="sectionblockcodecolored" %)pagebackground.css(%%) and add a reference to it from the (% class="sectionblockcodecolored" %)style.css(%%) component ( see the section [[E>>#5e]] for more information about how to add new components to the Skin )
240 1*. override the (% class="sectionblockcodecolored" %)mybaseskin.css(%%) component ( where mybaseskin is the name of the current Skin - for example: (% class="sectionblockcodecolored" %)albatross.css(%%), (% class="sectionblockcodecolored" %)toucan.css(%%) or (% class="sectionblockcodecolored" %)colibri.css(%%) )
241 1. paste the following code inside the {{html}}<acronym title="Cascading Style Sheets">CSS</acronym>{{/html}} component:(((
242 {{code language="css"}}
243 body{
Raluca Stavro 1.1 244 background-image: url($xwiki.getSkinFile("myimage.jpg"));
MariusButuc 11.1 245 }
246 {{/code}}
247 )))
Raluca Stavro 1.1 248
249 Open any page in view mode and you will notice that the the background of the page contains your image.
250 Have fun taking advantage of the power of XWiki Skins!
251
MariusButuc 11.1 252 == More about XWiki Skins ==
253
Raluca Stavro 9.1 254 In order to find more about XWiki Skins, check the [[Skins Tutorial>>AdminGuide.Skins]] from inside the Admin Guide and the [[Skins Tutorial>>Features.Skins]] from inside the User Guide
255
MariusButuc 11.1 256 == Further reading ==
Raluca Stavro 1.1 257
MariusButuc 11.1 258 * the [[XWiki Data Model>>http://platform.xwiki.org/xwiki/bin/view/DevGuide/DataModel]]
Vincent Massol 12.2 259 * using the [[Skin Editor Application>>extensions:Extension.Skin Editor Application]]
MariusButuc 11.1 260 * [[edit only one object>>http://dev.xwiki.org/xwiki/bin/view/Drafts/EditOneObject]]

Get Connected