44 | | === Trac 0.10 and below === |
45 | | |
46 | | ==== Site Header & Footer ==== |
47 | | In the environment folder for each Trac project there should be a directory called {{{templates}}}. This folder contains files {{{site_header.cs}}} and {{{site_footer.cs}}}. Users can customize their Trac site by adding the required HTML markup to these files. The content of these two files will be placed immediately following the opening {{{<body>}}} tag and immediately preceding the closing {{{</body>}}} tag of each page in the site, respectively. |
48 | | |
49 | | These files may contain static HTML, though if users desire to have dynamically generated content they can make use of the [http://www.clearsilver.net/ ClearSilver] templating language from within the pages as well. When you need to see what variables are available to the template, append the query string `?hdfdump=1` to the URL of your Trac site. This will display a structured view of the template data. |
50 | | |
51 | | Static content, needs to be put outside the ClearSilver tag. For example: |
52 | | |
53 | | {{{ |
54 | | <?cs |
55 | | ######################################################################### |
56 | | # Site footer - Contents are automatically inserted after main Trac HTML |
57 | | ?> |
58 | | <h1>TEST FOOTER</h1> |
59 | | }}} |
60 | | |
61 | | ==== Site CSS ==== |
62 | | The primary means to adjust the layout of a Trac site is to add [http://www.w3.org/TR/REC-CSS2/ CSS] style rules that overlay the default rules. This is best done by editing the `site_css.cs` file in the enviroment's `templates` directory. The content of that template gets inserted into a `<style type="text/css"></style>` element on every HTML page generated by Trac. |
63 | | |
64 | | While you can add your custom style rules directly to the `site_css.cs` file, it is recommended that you simply reference an external style sheet, thereby enabling browsers to cache the CSS file instead of transmitting the rules with every response. |
65 | | |
66 | | The following example would import a style sheet located in the `style` root directory of your host: |
67 | | {{{ |
68 | | @import url(/style/mytrac.css); |
69 | | }}} |
70 | | |
71 | | You can use a !ClearSilver variable to reference a style sheet stored in the project environment's `htdocs` directory: |
72 | | {{{ |
73 | | @import url(<?cs var:chrome.href ?>/site/style.css); |
74 | | }}} |
75 | | |
76 | | Note that this references `htdocs/style.css`, not |
77 | | `htdocs/site/style.css`. |
78 | | |
79 | | === Trac 0.11 and above === |
80 | | |
81 | | Since release [milestone:0.11], Trac is using [http://genshi.edgewall.org Genshi] as the templating engine.[[BR]] |
82 | | Therefore, customization of the interface is achieved in a slightly different way than it used to be with the ClearSilver templating engine. |
83 | | |
84 | | Documentation is yet to be written, in the meantime the following tip should work. |
| 58 | Trac is using [http://genshi.edgewall.org Genshi] as the templating engine. Documentation is yet to be written, in the meantime the following tip should work. |
152 | | <html> |
153 | | <head><title>Available Projects</title></head> |
154 | | <body> |
155 | | <h1>Available Projects</h1> |
156 | | <ul><?cs |
157 | | each:project = projects ?><li><?cs |
158 | | if:project.href ?> |
159 | | <a href="<?cs var:project.href ?>" title="<?cs var:project.description ?>"> |
160 | | <?cs var:project.name ?></a><?cs |
161 | | else ?> |
162 | | <small><?cs var:project.name ?>: <em>Error</em> <br /> |
163 | | (<?cs var:project.description ?>)</small><?cs |
164 | | /if ?> |
165 | | </li><?cs |
166 | | /each ?> |
167 | | </ul> |
168 | | </body> |
| 126 | <!DOCTYPE html |
| 127 | PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 128 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 129 | <html xmlns="http://www.w3.org/1999/xhtml" |
| 130 | xmlns:py="http://genshi.edgewall.org/" |
| 131 | xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 132 | <head> |
| 133 | <title>Available Projects</title> |
| 134 | </head> |
| 135 | <body> |
| 136 | <h1>Available Projects</h1> |
| 137 | <ul> |
| 138 | <li py:for="project in projects" py:choose=""> |
| 139 | <a py:when="project.href" href="$project.href" |
| 140 | title="$project.description">$project.name</a> |
| 141 | <py:otherwise> |
| 142 | <small>$project.name: <em>Error</em> <br /> ($project.description)</small> |
| 143 | </py:otherwise> |
| 144 | </li> |
| 145 | </ul> |
| 146 | </body> |
202 | | == Main Templates == |
203 | | |
204 | | It is also possible to use your own modified versions of the Trac [http://www.clearsilver.net/ ClearSilver] templates. Note though that this technique is not recommended because it makes upgrading Trac rather problematic: there are unfortunately several dependencies between the templates and the application code, such as the name of form fields and the structure of the template data, and these are likely to change between different versions of Trac. |
205 | | |
206 | | If you absolutely need to use modified templates, copy the template files from the default templates directory (usually in found in `$prefix/share/trac/templates`) into the `templates` directory of the project environment. Then modify those copies to get the desired results. |
207 | | |
208 | | |
209 | | == Adding Google Adsense Services To Your Trac == |
210 | | === Google Adsense For Content - Ads === |
211 | | It's actually pretty simple now that I know it, here it goes. |
212 | | On your trac environment directory, edit '''`site_css.cs`''' and put this inside: |
213 | | {{{ |
214 | | #!css |
215 | | <?cs |
216 | | ################################################################## |
217 | | # Site CSS - Place custom CSS, including overriding styles here. |
218 | | ?> |
219 | | /* For Mozilla and Safari */ |
220 | | *>#content { |
221 | | padding: 0; |
222 | | margin: 15px 140px 0 15px; |
223 | | text-align: left; |
224 | | min-height: 770px; |
225 | | } |
226 | | |
227 | | /* For IE */ |
228 | | * html #content { |
229 | | padding: 0; |
230 | | margin: 15px 140px 0 15px; |
231 | | text-align: left; |
232 | | height: 770px; |
233 | | } |
234 | | |
235 | | #ads { |
236 | | position: absolute; |
237 | | top: 170px; |
238 | | right: 10px; |
239 | | width: 140px; |
240 | | z-index: 1; |
241 | | text-align: right; |
242 | | } |
243 | | }}} |
244 | | Now a bit of explanation. Settings are of course, of topic, if you have doubts, there's a CSS link above in this page, click it, even so I'll explain parts. |
245 | | |
246 | | First we override '''`#content`''', trac's main content div id so we can have space for our ads. The most important part is that '''`140px`''', our right margin. We also set a minimun height(`min-height`) for Mozilla and Safary browsers and `height` for IE browser or else the ads would be on top of the footer in case the wiki page is small enough, which explains why there are two '''`#content`'''. Because IE doesn't respect `min-height`, so it's just work arround that. |
247 | | |
248 | | The '''`width`''' in '''`#ads`''' should only be set if you intend to have multiple ad spaces, for example, a Skyscraper Google Ad, and also a 'Use Firefox...' that google also makes available. If it wasn't set, both ads would show up side by side, wich is not good '''`;]`'''. If you only intend on using a single Skyscrapper Google Ad, you should ommit '''`width`''', why, because if a user has the firefox Ad-Block plugin, and he blocks all ad content from google he'll see the wiki pages with the full width. Neat right, this way we make everyone happy. |
249 | | |
250 | | Now we'll need to add the Google Ads code somewhere right? Edit '''`site_footer.cs`''', and next is an example: |
251 | | {{{ |
252 | | #!text/html |
253 | | <?cs |
254 | | ######################################################################### |
255 | | # Site footer - Contents are automatically inserted after main Trac HTML |
256 | | ?> |
257 | | <div id="ads"> |
258 | | <!--- Start of Google Ad Code --> |
259 | | YOU WOULD PASTE IT HERE |
260 | | |
261 | | |
262 | | <!--- End of Google Ad Code --> |
263 | | </div> |
264 | | }}} |
265 | | |
266 | | Another example is those ads moving up/down everytime you scroll: |
267 | | {{{ |
268 | | #!text/html |
269 | | <?cs |
270 | | ######################################################################### |
271 | | # Site footer - Contents are automatically inserted after main Trac HTML |
272 | | ?> |
273 | | <div id="ads"> |
274 | | <!--- Start of Google Ad Code --> |
275 | | YOU WOULD PASTE IT HERE |
276 | | <!--- End of Google Ad Code --> |
277 | | </div> |
278 | | |
279 | | <!-- ********************************************************************* |
280 | | * You may use this code for free on any web page provided that |
281 | | * these comment lines and the following credit remain in the code. |
282 | | * From http://www.javascript-fx.com |
283 | | **************************************************************** --> |
284 | | <script type="text/javascript"> |
285 | | <!-- |
286 | | function JSFX_FloatTopRight() |
287 | | { |
288 | | var startX = 10, startY = 160; |
289 | | var ns = (navigator.appName.indexOf("Netscape") != -1); |
290 | | var d = document; |
291 | | var px = document.layers ? "" : "px"; |
292 | | function ml(id) |
293 | | { |
294 | | var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id]; |
295 | | if(d.layers)el.style=el; |
296 | | el.sP=function(x,y){this.style.right=x+px;this.style.top=y+px;}; |
297 | | el.x = startX; el.y = startY; |
298 | | return el; |
299 | | } |
300 | | window.stayTopRight=function() |
301 | | { |
302 | | var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop; |
303 | | var dY = (pY > startY) ? pY : startY; |
304 | | ftlObj.y += (dY - ftlObj.y)/8; |
305 | | ftlObj.sP(ftlObj.x, ftlObj.y); |
306 | | setTimeout("stayTopRight()", 40); |
307 | | } |
308 | | ftlObj = ml("ads"); |
309 | | stayTopRight(); |
310 | | } |
311 | | JSFX_FloatTopRight(); |
312 | | //--> |
313 | | </script> |
314 | | }}} |
315 | | |
316 | | The most important line is this one: |
317 | | {{{ |
318 | | ftlObj = ml("ads"); |
319 | | }}} |
320 | | You must match your ads DIV name: |
321 | | {{{ |
322 | | ftlObj = ml("<your_ads_div_name_here>"); |
323 | | }}} |
324 | | |
325 | | === Google Adsense for Search - Search Boxes === |
326 | | As a follow up on the [http://projects.edgewall.com/trac/wiki/TracInterfaceCustomization#GoogleAdsenseForContentAds previous subject], I'll introduce one more way to add income to your Trac env, replacing trac's search box seen on the top right of trac's header for one that Google Adsense provides. First generate the code you need by logging into [http://google.com/adsense Google Adsense] and selecting "Google Adsense for Search", there you find enough info on how to generate it. |
327 | | |
328 | | Now we'll need to add an additional DIV to '''`site_css.cs`''', here it goes: |
329 | | {{{ |
330 | | #!css |
331 | | <?cs |
332 | | ################################################################## |
333 | | # Site CSS - Place custom CSS, including overriding styles here. |
334 | | ?> |
335 | | #GoogleSearch { |
336 | | position: absolute; |
337 | | top: 3px; |
338 | | right: 3px; |
339 | | z-index: 1; |
340 | | } |
341 | | }}} |
342 | | |
343 | | Now you'll need to add the previous generated search box HTML code somewhere. Edit '''`site_header.cs`''' to look something like: |
344 | | {{{ |
345 | | #!text/html |
346 | | <?cs |
347 | | #################################################################### |
348 | | # Site header - Contents are automatically inserted above Trac HTML |
349 | | ?> |
350 | | <div id="GoogleSearch"> |
351 | | <!--- Start of Google Search Box Code --> |
352 | | YOU WOULD PASTE IT HERE |
353 | | <!--- End of Google Search Box Code --> |
354 | | </div> |
355 | | }}} |
356 | | What happens is that the '''`#GoogleSearch`''' DIV is placed on top of Trac's search box, and by this, replacing it. Do NOTE that Trac's search will still be available, you'll just need to click the search button on the navbar. |
357 | | |
358 | | === In Action === |
359 | | Want to see it in action, drop an eye on [http://dev.ufsoft.org/TracWikiTemplates Trac WikiTemplates Plugin] site. |
360 | | |
361 | | '''IMPORTANT: Do read Google's [https://www.google.com/adsense/localized-terms Terms & Conditions], your account will be frozen/deleted and you WON'T GET any amount you had previously earned if you don't FOLLOW THEM.''' |
362 | | |