wiki:TipAndDoc/project/trac/templates

Version 6 (modified by mitty, 14 years ago) (diff)

--

Templates for Trac

  • Trac 0.11以降を対象

parameters

  • 設定例
    • trac.fcgiのURLは「/trac」
      • ScriptAlias /trac /usr/local/trac/cgi-bin/trac.fcgi
    • 環境名は「test」
      • インストール先は /path/to/trac/test
    • htdocs_location = /static/trac
      • trac.iniで設定
    • Alias /static/trac /var/www/trac
  • ${href.chrome()}
    • => /trac/test/chrome
  • ${href.chrome('common/style.css')}
    • => /trac/test/chrome/common/style.css -> /var/www/trac/style.css
  • ${href.chrome('site/style.css')}
    • => /trac/test/chrome/site/style.css -> /path/to/trac/test/htdocs/style.css
  • ${chrome.htdocs_location}
    • => /static/trac/

site.html

  • Trac 0.11で新しく環境を作成すると、/path/to/trac/env/templates/site.htmlが自動生成される。
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:py="http://genshi.edgewall.org/" py:strip="">
      <!--! Custom match templates go here -->
    </html>
    
    • globalのtrac.iniなどで指定([inherit] templates_dir)したsite.htmlは各環境ごとのsite.htmlで上書きされるため、0.11からupgradeした場合などは注意が必要。
  • 0.12ではsite.html.sampleが自動生成される
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:xi="http://www.w3.org/2001/XInclude"
          xmlns:py="http://genshi.edgewall.org/"
          py:strip="">
      <!--!
        This file allows customizing the appearance of the Trac installation.
        Add your customizations here and rename the file to site.html. Note that
        it will take precedence over a global site.html placed in the directory
        specified by [inherit] templates_dir.
        
        More information about site appearance customization can be found here:
        
          http://trac.edgewall.org/wiki/TracInterfaceCustomization#SiteAppearance
      -->
    </html>
    
  • site.htmlを空のファイル(0byte)にするとエラーになる
    TemplateSyntaxError: no element found: line 1, column 0 (/path/to/global/trac/templates/site.html, line 1)
    

  • site.html
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:xi="http://www.w3.org/2001/XInclude"
          xmlns:py="http://genshi.edgewall.org/"
          py:strip="">
      <!--! Add site-specific style sheet -->
      <head py:match="head" py:attrs="select('@*')">
        ${select('*|comment()|text()')}
        <link rel="stylesheet" type="text/css"
              href="${href.chrome('site/style.css')}" />
      </head>
    </html>
    
    • => diff of wiki:WikiStart
      @@ -3,6 +3,8 @@
         
         
       
      +  
      +
       
         <head>
           <title>
      @@ -30,6 +32,7 @@
               $(".foldable").enableFolding(true, true);
             });
           </script>
      +    <link rel="stylesheet" type="text/css" href="/trac/testenv/chrome/site/style.css" />
         </head>
         <body>
           <div id="banner">
      

CSSの追加

  • 0.12では /path/to/trac/ENV_NAME/htdocs/ の共有ディレクトリ(trac.iniにおける[inherit] templates_dirなどで指定できるディレクトリと同等の意味を持つもの)版が設定できない
    • => templates/site.htmlで「href="/static/htdocs/custom.css"」などと指定して、Apache側でAliasすることで回避
  • 設定例