<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>6.3. Template Customization</title><link rel="stylesheet" type="text/css" href="../../style.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><meta name="keywords" content="Bugzilla, Guide, installation, FAQ, administration, integration, MySQL, Mozilla, webtools"><link rel="home" href="index.html" title="The Bugzilla Guide - 4.4.6 Release"><link rel="up" href="customization.html" title="Chapter 6. Customizing Bugzilla"><link rel="prev" href="cust-skins.html" title="6.2. Custom Skins"><link rel="next" href="cust-change-permissions.html" title="6.4. Customizing Who Can Change What"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6.3. Template Customization</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="cust-skins.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Customizing Bugzilla</th><td width="20%" align="right"> <a accesskey="n" href="cust-change-permissions.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="cust-templates"></a>6.3. Template Customization</h2></div></div></div><p> Administrators can configure the look and feel of Bugzilla without having to edit Perl files or face the nightmare of massive merge conflicts when they upgrade to a newer version in the future. </p><p> Templatization also makes localized versions of Bugzilla possible, for the first time. It's possible to have Bugzilla's UI language determined by the user's browser. More information is available in <a class="xref" href="cust-templates.html#template-http-accept" title="6.3.6. Configuring Bugzilla to Detect the User's Language">Section 6.3.6, “Configuring Bugzilla to Detect the User's Language”</a>. </p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="template-directory"></a>6.3.1. Template Directory Structure</h3></div></div></div><p> The template directory structure starts with top level directory named <code class="filename">template</code>, which contains a directory for each installed localization. The next level defines the language used in the templates. Bugzilla comes with English templates, so the directory name is <code class="filename">en</code>, and we will discuss <code class="filename">template/en</code> throughout the documentation. Below <code class="filename">template/en</code> is the <code class="filename">default</code> directory, which contains all the standard templates shipped with Bugzilla. </p><div class="warning" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../images/warning.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> A directory <code class="filename">data/templates</code> also exists; this is where Template Toolkit puts the compiled versions of the templates from either the default or custom directories. <span class="emphasis"><em>Do not</em></span> directly edit the files in this directory, or all your changes will be lost the next time Template Toolkit recompiles the templates. </p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="template-method"></a>6.3.2. Choosing a Customization Method</h3></div></div></div><p> If you want to edit Bugzilla's templates, the first decision you must make is how you want to go about doing so. There are two choices, and which you use depends mainly on the scope of your modifications, and the method you plan to use to upgrade Bugzilla. </p><p> The first method of making customizations is to directly edit the templates found in <code class="filename">template/en/default</code>. This is probably the best way to go about it if you are going to be upgrading Bugzilla through Bzr, because if you then execute a <span class="command"><strong>bzr update</strong></span>, any changes you have made will be merged automagically with the updated versions. </p><div class="note" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> If you use this method, and Bzr conflicts occur during an update, the conflicted templates (and possibly other parts of your installation) will not work until they are resolved. </p></td></tr></table></div><p> The second method is to copy the templates to be modified into a mirrored directory structure under <code class="filename">template/en/custom</code>. Templates in this directory structure automatically override any identically-named and identically-located templates in the <code class="filename">default</code> directory. </p><div class="note" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> The <code class="filename">custom</code> directory does not exist at first and must be created if you want to use it. </p></td></tr></table></div><p> The second method of customization should be used if you use the overwriting method of upgrade, because otherwise your changes will be lost. This method may also be better if you are using the Bzr method of upgrading and are going to make major changes, because it is guaranteed that the contents of this directory will not be touched during an upgrade, and you can then decide whether to continue using your own templates, or make the effort to merge your changes into the new versions by hand. </p><p> Using this method, your installation may break if incompatible changes are made to the template interface. Such changes should be documented in the release notes, provided you are using a stable release of Bugzilla. If you use using unstable code, you will need to deal with this one yourself, although if possible the changes will be mentioned before they occur in the deprecations section of the previous stable release's release notes. </p><div class="note" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> Regardless of which method you choose, it is recommended that you run <span class="command"><strong>./checksetup.pl</strong></span> after editing any templates in the <code class="filename">template/en/default</code> directory, and after creating or editing any templates in the <code class="filename">custom</code> directory. </p></td></tr></table></div><div class="warning" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../images/warning.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> It is <span class="emphasis"><em>required</em></span> that you run <span class="command"><strong>./checksetup.pl</strong></span> after creating a new template in the <code class="filename">custom</code> directory. Failure to do so will raise an incomprehensible error message. </p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="template-edit"></a>6.3.3. How To Edit Templates</h3></div></div></div><div class="note" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> If you are making template changes that you intend on submitting back for inclusion in standard Bugzilla, you should read the relevant sections of the <a class="ulink" href="http://www.bugzilla.org/docs/developer.html" target="_top">Developers' Guide</a>. </p></td></tr></table></div><p> The syntax of the Template Toolkit language is beyond the scope of this guide. It's reasonably easy to pick up by looking at the current templates; or, you can read the manual, available on the <a class="ulink" href="http://www.template-toolkit.org" target="_top">Template Toolkit home page</a>. </p><p> One thing you should take particular care about is the need to properly HTML filter data that has been passed into the template. This means that if the data can possibly contain special HTML characters such as <, and the data was not intended to be HTML, they need to be converted to entity form, i.e. &lt;. You use the 'html' filter in the Template Toolkit to do this (or the 'uri' filter to encode special characters in URLs). If you forget, you may open up your installation to cross-site scripting attacks. </p><p> Editing templates is a good way of doing a <span class="quote">“<span class="quote">poor man's custom fields</span>”</span>. For example, if you don't use the Status Whiteboard, but want to have a free-form text entry box for <span class="quote">“<span class="quote">Build Identifier</span>”</span>, then you can just edit the templates to change the field labels. It's still be called status_whiteboard internally, but your users don't need to know that. </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="template-formats"></a>6.3.4. Template Formats and Types</h3></div></div></div><p> Some CGI's have the ability to use more than one template. For example, <code class="filename">buglist.cgi</code> can output itself as RDF, or as two formats of HTML (complex and simple). The mechanism that provides this feature is extensible. </p><p> Bugzilla can support different types of output, which again can have multiple formats. In order to request a certain type, you can append the &ctype=<contenttype> (such as rdf or html) to the <code class="filename"><cginame>.cgi</code> URL. If you would like to retrieve a certain format, you can use the &format=<format> (such as simple or complex) in the URL. </p><p> To see if a CGI supports multiple output formats and types, grep the CGI for <span class="quote">“<span class="quote">get_format</span>”</span>. If it's not present, adding multiple format/type support isn't too hard - see how it's done in other CGIs, e.g. config.cgi. </p><p> To make a new format template for a CGI which supports this, open a current template for that CGI and take note of the INTERFACE comment (if present.) This comment defines what variables are passed into this template. If there isn't one, I'm afraid you'll have to read the template and the code to find out what information you get. </p><p> Write your template in whatever markup or text style is appropriate. </p><p> You now need to decide what content type you want your template served as. The content types are defined in the <code class="filename">Bugzilla/Constants.pm</code> file in the <code class="filename">contenttypes</code> constant. If your content type is not there, add it. Remember the three- or four-letter tag assigned to your content type. This tag will be part of the template filename. </p><div class="note" style="margin-left: 1em; margin-right: 1em"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.gif"></td><th align="left"></th></tr><tr><td align="left" valign="top"><p> After adding or changing a content type, it's suitable to edit <code class="filename">Bugzilla/Constants.pm</code> in order to reflect the changes. Also, the file should be kept up to date after an upgrade if content types have been customized in the past. </p></td></tr></table></div><p> Save the template as <code class="filename"><stubname>-<formatname>.<contenttypetag>.tmpl</code>. Try out the template by calling the CGI as <code class="filename"><cginame>.cgi?format=<formatname>&ctype=<type></code> . </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="template-specific"></a>6.3.5. Particular Templates</h3></div></div></div><p> There are a few templates you may be particularly interested in customizing for your installation. </p><p> <span class="command"><strong>index.html.tmpl</strong></span>: This is the Bugzilla front page. </p><p> <span class="command"><strong>global/header.html.tmpl</strong></span>: This defines the header that goes on all Bugzilla pages. The header includes the banner, which is what appears to users and is probably what you want to edit instead. However the header also includes the HTML HEAD section, so you could for example add a stylesheet or META tag by editing the header. </p><p> <span class="command"><strong>global/banner.html.tmpl</strong></span>: This contains the <span class="quote">“<span class="quote">banner</span>”</span>, the part of the header that appears at the top of all Bugzilla pages. The default banner is reasonably barren, so you'll probably want to customize this to give your installation a distinctive look and feel. It is recommended you preserve the Bugzilla version number in some form so the version you are running can be determined, and users know what docs to read. </p><p> <span class="command"><strong>global/footer.html.tmpl</strong></span>: This defines the footer that goes on all Bugzilla pages. Editing this is another way to quickly get a distinctive look and feel for your Bugzilla installation. </p><p> <span class="command"><strong>global/variables.none.tmpl</strong></span>: This defines a list of terms that may be changed in order to <span class="quote">“<span class="quote">brand</span>”</span> the Bugzilla instance In this way, terms like <span class="quote">“<span class="quote">bugs</span>”</span> can be replaced with <span class="quote">“<span class="quote">issues</span>”</span> across the whole Bugzilla installation. The name <span class="quote">“<span class="quote">Bugzilla</span>”</span> and other words can be customized as well. </p><p> <span class="command"><strong>list/table.html.tmpl</strong></span>: This template controls the appearance of the bug lists created by Bugzilla. Editing this template allows per-column control of the width and title of a column, the maximum display length of each entry, and the wrap behaviour of long entries. For long bug lists, Bugzilla inserts a 'break' every 100 bugs by default; this behaviour is also controlled by this template, and that value can be modified here. </p><p> <span class="command"><strong>bug/create/user-message.html.tmpl</strong></span>: This is a message that appears near the top of the bug reporting page. By modifying this, you can tell your users how they should report bugs. </p><p> <span class="command"><strong>bug/process/midair.html.tmpl</strong></span>: This is the page used if two people submit simultaneous changes to the same bug. The second person to submit their changes will get this page to tell them what the first person did, and ask if they wish to overwrite those changes or go back and revisit the bug. The default title and header on this page read "Mid-air collision detected!" If you work in the aviation industry, or other environment where this might be found offensive (yes, we have true stories of this happening) you'll want to change this to something more appropriate for your environment. </p><p> <span class="command"><strong>bug/create/create.html.tmpl</strong></span> and <span class="command"><strong>bug/create/comment.txt.tmpl</strong></span>: You may not wish to go to the effort of creating custom fields in Bugzilla, yet you want to make sure that each bug report contains a number of pieces of important information for which there is not a special field. The bug entry system has been designed in an extensible fashion to enable you to add arbitrary HTML widgets, such as drop-down lists or textboxes, to the bug entry page and have their values appear formatted in the initial comment. A hidden field that indicates the format should be added inside the form in order to make the template functional. Its value should be the suffix of the template filename. For example, if the file is called <code class="filename">create-cust.html.tmpl</code>, then </p><pre class="programlisting"><input type="hidden" name="format" value="cust"></pre><p> should be used inside the form. </p><p> An example of this is the mozilla.org <a class="ulink" href="http://landfill.bugzilla.org/bugzilla-tip/enter_bug.cgi?product=WorldControl;format=guided" target="_top">guided bug submission form</a>. The code for this comes with the Bugzilla distribution as an example for you to copy. It can be found in the files <code class="filename">create-guided.html.tmpl</code> and <code class="filename">comment-guided.html.tmpl</code>. </p><p> So to use this feature, create a custom template for <code class="filename">enter_bug.cgi</code>. The default template, on which you could base it, is <code class="filename">custom/bug/create/create.html.tmpl</code>. Call it <code class="filename">create-<formatname>.html.tmpl</code>, and in it, add widgets for each piece of information you'd like collected - such as a build number, or set of steps to reproduce. </p><p> Then, create a template like <code class="filename">custom/bug/create/comment.txt.tmpl</code>, and call it <code class="filename">comment-<formatname>.txt.tmpl</code>. This template should reference the form fields you have created using the syntax <code class="filename">[% form.<fieldname> %]</code>. When a bug report is submitted, the initial comment attached to the bug report will be formatted according to the layout of this template. </p><p> For example, if your custom enter_bug template had a field </p><pre class="programlisting"><input type="text" name="buildid" size="30"></pre><p> and then your comment.txt.tmpl had </p><pre class="programlisting">BuildID: [% form.buildid %]</pre><p> then something like </p><pre class="programlisting">BuildID: 20020303</pre><p> would appear in the initial comment. </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="template-http-accept"></a>6.3.6. Configuring Bugzilla to Detect the User's Language</h3></div></div></div><p>Bugzilla honours the user's Accept: HTTP header. You can install templates in other languages, and Bugzilla will pick the most appropriate according to a priority order defined by you. Many language templates can be obtained from <a class="ulink" href="http://www.bugzilla.org/download.html#localizations" target="_top">http://www.bugzilla.org/download.html#localizations</a>. Instructions for submitting new languages are also available from that location. </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="cust-skins.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="customization.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="cust-change-permissions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6.2. Custom Skins </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6.4. Customizing Who Can Change What</td></tr></table></div></body></html>