Changes between Initial Version and Version 1 of TracInterfaceCustomization

7/22/2007 8:33:50 PM (17 years ago)



  • TracInterfaceCustomization

    v1 v1  
     1= Customizing the Trac Interface = 
     4== Introduction == 
     5This 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. 
     7== Project Logo and Icon == 
     8The easiest parts of the Trac interface to customize are the logo and the site icon.  Both of these can be configured with settings in [wiki:TracIni trac.ini]. 
     10The 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'') 
     12 ''Note: you can actually put the logo and icon anywhere on your server (as long as it's accessible through the web server), and use their absolute or server-relative URLs in the configuration.'' 
     14Now configure the appropriate section of your [wiki:TracIni trac.ini]: 
     16=== Logo === 
     17Change 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). 
     21src = site/my_logo.gif 
     22alt = My Project 
     23width = 300 
     24height = 100 
     27=== Icon === 
     28Icons 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. 
     32icon = site/my_icon.ico 
     35Note 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: 
     39icon = /favicon.ico 
     42== Site Header & Footer == 
     44In 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. 
     46These 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. 
     48== Site CSS == 
     49The primary means to adjust the layout of a Trac site is to 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. 
     51While 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. 
     53The following example would import a style sheet located in the `style` root directory of your host: 
     55@import url(/style/mytrac.css); 
     58You can use a !ClearSilver variable to reference a style sheet stored in the project environment's `htdocs` directory: 
     60@import url(<?cs var:chrome.href ?>/site/style.css); 
     63== Project List == 
     64You can use a custom ClearSilver template to display the list of projects if you are using Trac with multiple projects.   
     66The following is the basic template used by Trac to display a list of links to the projects.  For projects that could not be loaded it displays an error message. You can use this as a starting point for your own index template. 
     71<head><title>Available Projects</title></head> 
     73 <h1>Available Projects</h1> 
     74 <ul><?cs 
     75 each:project = projects ?><li><?cs 
     76  if:project.href ?> 
     77   <a href="<?cs var:project.href ?>" title="<?cs var:project.description ?>"> 
     78    <?cs ?></a><?cs 
     79  else ?> 
     80   <small><?cs ?>: <em>Error</em> <br /> 
     81   (<?cs var:project.description ?>)</small><?cs 
     82  /if ?> 
     83  </li><?cs 
     84 /each ?> 
     85 </ul> 
     90Once you've created your custom template you will need to configure the webserver to tell Trac where the template is located: 
     92For [wiki:TracFastCgi FastCGI]: 
     94FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects \ 
     95              -initial-env TRAC_ENV_INDEX_TEMPLATE=/path/to/template 
     98For [wiki:TracModPython mod_python]: 
     100PythonOption TracEnvIndexTemplate /path/to/template 
     103For [wiki:TracCgi CGI]: 
     105SetEnv TRAC_ENV_INDEX_TEMPLATE /path/to/template 
     109== Main Templates == 
     111It 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. 
     113If 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. 
     116See also TracGuide, TracIni