Edgewall Software

Version 13 (modified by Pedro Algarvio <ufs@…>, 14 years ago) ( diff )

This page documents the 1.4 (latest stable) release. Documentation for other releases can be found here.

Customizing the Trac Interface

Introduction

This page is meant to give users suggestions on how they can customize the look of Trac. Topics on this page cover editing the HTML templates and CSS files, but not the program code itself. The topics are intended to show users how they can modify the look of Trac to meet their specific needs. Suggestions for changes to Trac's interface applicable to all users should be filed as tickets, not listed on this page.

Project Logo and Icon

The easiest parts of the Trac interface to customize are the logo and the site icon. Both of these can be configured with settings in trac.ini.

The logo or icon image should be put in a folder named "htdocs" in your project's environment folder. (Note: in projects created with a Trac version prior to 0.9 you will need to create this folder)

Now configure the appropriate section of your trac.ini:

Change the src setting to site/ followed by the name of your image file. The width and height settings should be modified to match your image's dimensions (the Trac chrome handler uses "site/" for files within the project directory htdocs and "common/" for the common ones).

[header_logo]
src = site/my_logo.gif
alt = My Project
width = 300
height = 100

Icon

Icons should be a 16x16 image in .gif or .ico format. Change the icon setting to site/ followed by the name of your icon file. Icons will typically be displayed by your web browser next to the site's URL and in the Bookmarks menu.

[project]
icon = site/my_icon.ico

Note though that this icon is ignored by Internet Explorer, which only accepts a file named favicon.ico at the root of the host. To make the project icon work in both IE and other browsers, you can store the icon in the document root of the host, and reference it from trac.ini as follows:

[project]
icon = /favicon.ico

Site Header & Footer

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.

These files may contain static HTML, though if users desire to have dynamically generated content they can make use of the 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.

Site CSS

The primary means to adjust the layout of a Trac site is by add 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.

While you can add your custom style rules directory 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.

The following example would import a style sheet located in the style root directory of your host:

@import url(/style/mytrac.css);

You can use a ClearSilver variable to reference a style sheet stored in the project environment's htdocs directory:

@import url(<?cs var:chrome.href ?>/site/style.css);

Main Templates

It is also possible to use your own modified versions of the Trac 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.

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.

Adding Google Ads to your Trac

It's actually pretty simple now that I know it, here it goes. On your trac environment directory, edit site_css.cs and put this inside:

#content {
        padding: 0;
        margin: 15px 140px 0 15px;
        text-align: left;
        min-height: 770px;
}

#ads {
        position: absolute;
        top: 170px;
        right: 10px;
        width: 140px;
        z-index: 1;
        text-align: right;               
}

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. 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 or else the ads would be on top of the footer in case the wiki page is small enough.

Now we'll need to add the Google Ads code somewhere right? Edit site_footer.cs, and next is an example:

<div id="ads">
        <!--- Start of Google Ad Code -->
        YOU WOULD PASTE IT HERE
        <!--- End of Google Ad Code -->
</div>

NOTE: In IE the min-height(minimum-height) doesn't work, so if the wiki page is small enough, the footer will be overriden. If someone else finds a solution, please post it here. As a work arround you could also make the footer right margin bigger, leaving enough space for the ads.


See also TracGuide, TracIni

Note: See TracWiki for help on using the wiki.