bugzilla-4intranet/docs/en/html/cust-templates.html

916 lines
21 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Template Customization</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="The Bugzilla Guide - 3.4.2
Release"
HREF="index.html"><LINK
REL="UP"
TITLE="Customizing Bugzilla"
HREF="customization.html"><LINK
REL="PREVIOUS"
TITLE="Custom Skins"
HREF="cust-skins.html"><LINK
REL="NEXT"
TITLE="The Bugzilla Extension Mechanism"
HREF="cust-hooks.html"></HEAD
><BODY
CLASS="section"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Bugzilla Guide - 3.4.2
Release</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="cust-skins.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 6. Customizing Bugzilla</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="cust-hooks.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="cust-templates"
>6.2. Template Customization</A
></H1
><P
>&#13; 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
>&#13; 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
HREF="cust-templates.html#template-http-accept"
>Section 6.2.6</A
>.
</P
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="template-directory"
>6.2.1. Template Directory Structure</A
></H2
><P
>&#13; The template directory structure starts with top level directory
named <TT
CLASS="filename"
>template</TT
>, 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 <TT
CLASS="filename"
>en</TT
>,
and we will discuss <TT
CLASS="filename"
>template/en</TT
> throughout
the documentation. Below <TT
CLASS="filename"
>template/en</TT
> is the
<TT
CLASS="filename"
>default</TT
> directory, which contains all the
standard templates shipped with Bugzilla.
</P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; A directory <TT
CLASS="filename"
>data/templates</TT
> also exists;
this is where Template Toolkit puts the compiled versions of
the templates from either the default or custom directories.
<EM
>Do not</EM
> 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"
><H2
CLASS="section"
><A
NAME="template-method"
>6.2.2. Choosing a Customization Method</A
></H2
><P
>&#13; 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
>&#13; The first method of making customizations is to directly edit the
templates found in <TT
CLASS="filename"
>template/en/default</TT
>.
This is probably the best way to go about it if you are going to
be upgrading Bugzilla through CVS, because if you then execute
a <B
CLASS="command"
>cvs update</B
>, any changes you have made will
be merged automagically with the updated versions.
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; If you use this method, and CVS 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
>&#13; The second method is to copy the templates to be modified
into a mirrored directory structure under
<TT
CLASS="filename"
>template/en/custom</TT
>. Templates in this
directory structure automatically override any identically-named
and identically-located templates in the
<TT
CLASS="filename"
>default</TT
> directory.
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; The <TT
CLASS="filename"
>custom</TT
> directory does not exist
at first and must be created if you want to use it.
</P
></TD
></TR
></TABLE
></DIV
><P
>&#13; 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 CVS 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
>&#13; 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"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; Regardless of which method you choose, it is recommended that
you run <B
CLASS="command"
>./checksetup.pl</B
> after
editing any templates in the <TT
CLASS="filename"
>template/en/default</TT
>
directory, and after creating or editing any templates in the
<TT
CLASS="filename"
>custom</TT
> directory.
</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/warning.gif"
HSPACE="5"
ALT="Warning"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; It is <EM
>required</EM
> that you run
<B
CLASS="command"
>./checksetup.pl</B
> after creating a new
template in the <TT
CLASS="filename"
>custom</TT
> directory. Failure
to do so will raise an incomprehensible error message.
</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="template-edit"
>6.2.3. How To Edit Templates</A
></H2
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; 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
HREF="http://www.bugzilla.org/docs/developer.html"
TARGET="_top"
>Developers'
Guide</A
>.
</P
></TD
></TR
></TABLE
></DIV
><P
>&#13; 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
HREF="http://www.template-toolkit.org"
TARGET="_top"
>Template Toolkit home
page</A
>.
</P
><P
>&#13; 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 &#60;, and the data was not intended to be HTML, they need to be
converted to entity form, i.e. &#38;lt;. You use the 'html' filter in the
Template Toolkit to do this. If you forget, you may open up
your installation to cross-site scripting attacks.
</P
><P
>&#13; Also note that Bugzilla adds a few filters of its own, that are not
in standard Template Toolkit. In particular, the 'url_quote' filter
can convert characters that are illegal or have special meaning in URLs,
such as &#38;, to the encoded form, i.e. %26. This actually encodes most
characters (but not the common ones such as letters and numbers and so
on), including the HTML-special characters, so there's never a need to
HTML filter afterwards.
</P
><P
>&#13; Editing templates is a good way of doing a <SPAN
CLASS="QUOTE"
>"poor man's custom
fields"</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"
>"Build Identifier"</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"
><H2
CLASS="section"
><A
NAME="template-formats"
>6.2.4. Template Formats and Types</A
></H2
><P
>&#13; Some CGI's have the ability to use more than one template. For example,
<TT
CLASS="filename"
>buglist.cgi</TT
> can output itself as RDF, or as two
formats of HTML (complex and simple). The mechanism that provides this
feature is extensible.
</P
><P
>&#13; Bugzilla can support different types of output, which again can have
multiple formats. In order to request a certain type, you can append
the &#38;ctype=&#60;contenttype&#62; (such as rdf or html) to the
<TT
CLASS="filename"
>&#60;cginame&#62;.cgi</TT
> URL. If you would like to
retrieve a certain format, you can use the &#38;format=&#60;format&#62;
(such as simple or complex) in the URL.
</P
><P
>&#13; To see if a CGI supports multiple output formats and types, grep the
CGI for <SPAN
CLASS="QUOTE"
>"get_format"</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
>&#13; 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
>&#13; Write your template in whatever markup or text style is appropriate.
</P
><P
>&#13; You now need to decide what content type you want your template
served as. The content types are defined in the
<TT
CLASS="filename"
>Bugzilla/Constants.pm</TT
> file in the
<TT
CLASS="filename"
>contenttypes</TT
>
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"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; After adding or changing a content type, it's suitable to edit
<TT
CLASS="filename"
>Bugzilla/Constants.pm</TT
> 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
>&#13; Save the template as <TT
CLASS="filename"
>&#60;stubname&#62;-&#60;formatname&#62;.&#60;contenttypetag&#62;.tmpl</TT
>.
Try out the template by calling the CGI as
<TT
CLASS="filename"
>&#60;cginame&#62;.cgi?format=&#60;formatname&#62;&#38;ctype=&#60;type&#62;</TT
> .
</P
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="template-specific"
>6.2.5. Particular Templates</A
></H2
><P
>&#13; There are a few templates you may be particularly interested in
customizing for your installation.
</P
><P
>&#13; <B
CLASS="command"
>index.html.tmpl</B
>:
This is the Bugzilla front page.
</P
><P
>&#13; <B
CLASS="command"
>global/header.html.tmpl</B
>:
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
>&#13; <B
CLASS="command"
>global/banner.html.tmpl</B
>:
This contains the <SPAN
CLASS="QUOTE"
>"banner"</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
>&#13; <B
CLASS="command"
>global/footer.html.tmpl</B
>:
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
>&#13; <B
CLASS="command"
>global/variables.none.tmpl</B
>:
This defines a list of terms that may be changed in order to
<SPAN
CLASS="QUOTE"
>"brand"</SPAN
> the Bugzilla instance In this way, terms
like <SPAN
CLASS="QUOTE"
>"bugs"</SPAN
> can be replaced with <SPAN
CLASS="QUOTE"
>"issues"</SPAN
>
across the whole Bugzilla installation. The name
<SPAN
CLASS="QUOTE"
>"Bugzilla"</SPAN
> and other words can be customized as well.
</P
><P
>&#13; <B
CLASS="command"
>list/table.html.tmpl</B
>:
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
>&#13; <B
CLASS="command"
>bug/create/user-message.html.tmpl</B
>:
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
>&#13; <B
CLASS="command"
>bug/process/midair.html.tmpl</B
>:
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
>&#13; <B
CLASS="command"
>bug/create/create.html.tmpl</B
> and
<B
CLASS="command"
>bug/create/comment.txt.tmpl</B
>:
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 <TT
CLASS="filename"
>create-cust.html.tmpl</TT
>, then
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#60;input type="hidden" name="format" value="cust"&#62;</PRE
></FONT
></TD
></TR
></TABLE
>
should be used inside the form.
</P
><P
>
An example of this is the mozilla.org
<A
HREF="http://landfill.bugzilla.org/bugzilla-tip/enter_bug.cgi?product=WorldControl&#38;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
<TT
CLASS="filename"
>create-guided.html.tmpl</TT
> and
<TT
CLASS="filename"
>comment-guided.html.tmpl</TT
>.
</P
><P
>&#13; So to use this feature, create a custom template for
<TT
CLASS="filename"
>enter_bug.cgi</TT
>. The default template, on which you
could base it, is
<TT
CLASS="filename"
>custom/bug/create/create.html.tmpl</TT
>.
Call it <TT
CLASS="filename"
>create-&#60;formatname&#62;.html.tmpl</TT
>, 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
>&#13; Then, create a template like
<TT
CLASS="filename"
>custom/bug/create/comment.txt.tmpl</TT
>, and call it
<TT
CLASS="filename"
>comment-&#60;formatname&#62;.txt.tmpl</TT
>. This
template should reference the form fields you have created using
the syntax <TT
CLASS="filename"
>[% form.&#60;fieldname&#62; %]</TT
>. 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
>&#13; For example, if your custom enter_bug template had a field
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#60;input type="text" name="buildid" size="30"&#62;</PRE
></FONT
></TD
></TR
></TABLE
>
and then your comment.txt.tmpl had
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>BuildID: [% form.buildid %]</PRE
></FONT
></TD
></TR
></TABLE
>
then something like
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>BuildID: 20020303</PRE
></FONT
></TD
></TR
></TABLE
>
would appear in the initial comment.
</P
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="template-http-accept"
>6.2.6. Configuring Bugzilla to Detect the User's Language</A
></H2
><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
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
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="cust-skins.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="cust-hooks.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Custom Skins</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="customization.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>The Bugzilla Extension Mechanism</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>