The basic principle is that the site.html is one file to contain all
your modifications. It usually works by the py:match (element of
attribute), and it allows you to modify the page as it renders - the
matches hook onto specific sections depending on what it tries to find
and modify. A site.html can contain any number of such py:match
sections for whatever you need to modify. This is all Genshi, so the
docs on the templating system can be found there.
Save the following content as 'site.html' inside your projects
templates directory (each Trac project can have their own site.html),
or in a shared location as specified by the '[inherit] templates_dir
=' setting in the project trac.ini:
==== Start cut
<html xmlns="
http://www.w3.org/1999/xhtml"
xmlns:py="
http://genshi.edgewall.org/"
xmlns:xi="
http://www.w3.org/2001/XInclude"
py:strip="">
<!--! Add modification sections below -->
<form py:match="div[@id='content' and @class='ticket']/form"
py:attrs="select('@*')"
py:if="req.environ['PATH_INFO']=='/newticket' and not 'preview' in
req.args">
<!-- Custom new ticket text goes here - example: -->
<p>Please make sure to search for existing tickets
before reporting a new one!</p>
${select('*')}
</form>
</html>
===== End cut
As a very quick intro to the templating details, here is what happens
on a general level:
- templates are just named, and will be pulled in where they are first
located on template path
- the main layout.html renders and 'pulls in' the specific template
(like ticket.html) to make the full page
- as it gets to the bottom of layout.html, it does an include call for
site.html
- site.html contains modification(s) that change the almost-completed
html page (stream)
- at the end the page is finished and sent to the user.
Now to the details of what this modification does:
- py:if = it is only interested in ticket.html template, and not
diplay in preview
- py:match = XPath query find the position of modification start - it
grabs the form on the page
- the newticket modification is itself a form, and gets inserted into
the page instead of the existing form
- this new form has information text, but is otherwise an empty form
(not very useful)
- py:attrs = select and use in new form all the orgininal <form>
attributes
- ${select('*')} = insert all elements (wildcard, so all content) from
original form
=> So, basically you have a new form replacing the orginal form, but
it pulls in the original attributes and the original content, but
manages to insert some informational text in the process.
Once you grasp the basics, it makes perfect sense. It is an incredibly
poweful way of doing page modifications - anything can be changed,
added and removed; all without the need to modify any of the default
Trac templates directly. And, it works just the same for any plugin
templates for that matter.
:::simon
https://www.coderesort.com