hgweb and templating
Jan Capek
jen at jikos.cz
Tue Dec 2 02:05:31 CST 2008
> Matt Mackall wrote:
>
> It is possible to add my own keys to the map?
>
> I'm trying to add some common header stuff in a "headerend" template
> like this:
>
> in my map file I have:
> headerend = headerend.tmpl
>
> in summary.tmpl I have:
>
> #header#
> <title>#repo|escape#: Summary</title>
> #headerend#
>
> in headerend.tmpl:
>
> </head>
> <body>
>
> <h1>Welcome</h1>
>
> But the "#headerend#" string is just replaced with an empty string.
>
> --
> Trygve
>
Hi,
I have just subscribed to the mailing list and seen your post, so I am
sorry for not replying to it directly.
I have lately done something similar. Essentially, the problem is that the
set of defined templating keywords has to be known to the template engine.
I am not a guru here, but here is what I had to do to introduce a new
template element:
- modify hgweb_mod.py and register a new template keyword - required
registering the template callback - look at for example at the 'footer'
implementation
- modify the .tmpl files to use it (that's what you did)
Anybody knows a more simple approach?
To give you an idea, attached is a small patch that introduces 'logo'
support based on the hgrc configuration.
Cheers,
Jan
-------------- next part --------------
logo_{alt,src,link} templates for hgweb
- hgrc supports a new configuration parameters that allow setting logo
template. This template is than available for use in the web
interface .tmpl files.
- example configuration:
[web]
# customized templates for that use the logo
templates = /srv/www/hgweb-templates/
# static files modified also site specific
static = /srv/www/example.org/hg/static
# custom style tailored from git and extended with logo
style = git-web-with-logo
# logo settings
logo_link = http://hg.example.org/
# the logo has to be stored into /srv/www/example.org/hg/static
logo_src = hg-logo.png
logo_alt = Some alt text when logo is missing
Index: hgweb/hgweb_mod.py
===================================================================
--- hgweb.orig/hgweb_mod.py 2008-11-27 14:46:52.000000000 +0100
+++ hgweb/hgweb_mod.py 2008-11-27 14:47:30.000000000 +0100
@@ -305,6 +305,14 @@
def motd(**map):
yield self.config("web", "motd", "")
+ def logo(**map):
+ yield tmpl("logo",
+ logo_src = self.config('web', 'logo_src',''),
+ logo_alt = self.config('web', 'logo_alt','No logo'),
+ logo_link = self.config('web', 'logo_link',
+ 'http://www.selenic.com/mercurial'),
+ **map)
+
def sessionvars(**map):
fields = []
if 'style' in req.form:
@@ -339,6 +347,7 @@
"header": header,
"footer": footer,
"motd": motd,
+ "logo": logo,
"sessionvars": sessionvars
})
return tmpl
More information about the Mercurial
mailing list