Edgewall Software

Changes between Initial Version and Version 1 of CookBook/SiteHtml/Jinja2


Ignore:
Timestamp:
Feb 24, 2024, 4:35:47 AM (3 months ago)
Author:
Jun Omae
Comment:

Add cookbook page for site_*.html files using Jinja2

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/SiteHtml/Jinja2

    v1 v1  
     1= Interface Customization using site_*.html files
     2
     3This page collects useful snippets for inclusion in a project `site_head.html`, `site_header.html` and `site_footer.html` files.
     4
     5== Quicksearch for tickets only
     6
     7When no search filters are provided, Trac searches using all filters. This snippets adds a filter to the quicksearch that restricts searches to tickets only by default using `site_header.html`. More can of course be added by user after initial search:
     8
     9{{{
     10#!xml
     11<input type="hidden" name="ticket" value="on" form="search" />
     12}}}
     13
     14== Add licensing information when adding attachments
     15
     16If adding attachments to your Trac site requires people to agree to some licensing terms, you can add the terms of the license on the "Add attachments" page using `site_head.html` as follows:
     17
     18{{{#!html+jinja
     19{% raw %}<script>
     20jQuery(function($) {
     21    var terms = $('<p>').text('By submitting a file here, you accept that we can do whatever we want with it...');
     22    $('form#attachment .buttons').before(terms);
     23});
     24</script>{% endraw %}
     25}}}
     26
     27Another approach is inserting content to the buttons of the attachment form using CSS:
     28
     29{{{#!html+jinja
     30{% raw %}<style>
     31form#attachment .buttons::before {
     32 display: block;
     33 margin: .5em 0;
     34 content: "By submitting a file here, you accept that we can do whatever we want with it...";
     35}
     36</style>{% endraw %}
     37}}}
     38
     39== Rename Roadmap header
     40
     41If your team would prefer to see a different title instead of Roadmap, add the following code to your `site_head.html` and restart the server. Don't forget to edit trac.ini to [TracNavigation change the link title].
     42
     43{{{#!html+jinja
     44# if req.path_info == '/roadmap':
     45<script>
     46jQuery(function($) {
     47    $('h1').text('Open Milestones');
     48});
     49</script>
     50# endif
     51}}}
     52
     53== Replace footer
     54
     55If you want to change the default footer, add the following code to your `site_head.html`. This snippet strips out the current one and puts in my own.
     56
     57{{{#!html+jinja
     58{% raw %}<script>
     59jQuery(function($) {
     60    $('#footer').html(`
     61        <hr />
     62        <a id="tracpowered" href="http://www.tnky.ca/">
     63          <img src="http://www.tnky.ca/TAI_tag.jpg"
     64                   style="border: none; height: 98px; width: 185px;" alt="TAI Powered" /></a>
     65        <p class="left">Base Software is <a href="/about"><strong>Trac 1.4.3</strong></a>
     66          <br />
     67           By Edgewall Software.</p>
     68        <p class="right">Visit Turnkey Automation at<br /><a href="http://www.tnky.ca/">
     69             http://www.tnky.ca/</a></p>
     70    `);
     71});
     72</script>{% endraw %}
     73}}}