CUSTOMIZE - Ability to provide Altered Templates via a Plugin

3 views
Skip to first unread message

Ilias Lazaridis

unread,
Sep 12, 2006, 6:41:58 PM9/12/06
to Trac Users
Can I use the ITemplateProvider to override the original templates
(e.g. wiki.cs)?

Or is there any other mechanism available to do so from within a
plugin?

I guess I could use a simple copy instruction like this:

#code
global-trac-template-folder = <function to get
global-trac-template-folder>
copy /templates/wiki.cs to global-trac-template-folder
alter permissions

but I would like to avoid this.

context: http://trac.edgewall.org/ticket/3704

.

--
http://lazaridis.com

Noah Kantrowitz

unread,
Sep 13, 2006, 4:46:27 AM9/13/06
to trac-...@googlegroups.com
Look at the TracTags plugin for how to override builtin templates.

--Noah

Ilias Lazaridis

unread,
Sep 14, 2006, 10:11:03 PM9/14/06
to Trac Users
Noah Kantrowitz wrote:
> On Sep 12, 2006, at 6:41 PM, Ilias Lazaridis wrote:
> > Can I use the ITemplateProvider to override the original templates
> > (e.g. wiki.cs)?
> >
> > Or is there any other mechanism available to do so from within a
> > plugin?
> >
> > I guess I could use a simple copy instruction like this:
> >
> > #code
> > global-trac-template-folder = <function to get
> > global-trac-template-folder>
> > copy /templates/wiki.cs to global-trac-template-folder
> > alter permissions
> >
> > but I would like to avoid this.
> >
> > context: http://trac.edgewall.org/ticket/3704
>
> Look at the TracTags plugin for how to override builtin templates.

http://muness.textdriven.com/svn/edu/tags-plugin/trunk/tractags/web_ui.py

It provides an own template and an own implementation of the
wiki-module. This depends additionally on changing the ini file:

"
Update your trac.ini with the following:

[trac]
default_handler = TagsWikiModule

[components]
trac.wiki.web_ui.wikimodule = disabled
tractags.* = enabled
"

Any other simpler solution?

(if possible reversible, e.g. if the plugin is deactivated, the
original template should become active again)?

.

--
http://lazaridis.com

Noah Kantrowitz

unread,
Sep 14, 2006, 10:33:39 PM9/14/06
to trac-...@googlegroups.com
Sorry, looks like Alec took that bit of hackery out. The way
ClearSilver looks for templates is by examining each folder in the
'hdf.loadpaths' HDF variable. Normally the project templates folder
and the central templates folder are the first two items in this
list, with plugin folders being added below that. If you munged this
list so your folder appears first, you can mask out other templates.
As a probably much cleaner way to do it, you can just make a request
filter that does something like this:
{{{
def post_process_request(self, req, template, content_type):
if template == 'wiki.cs':
template = 'mytemplate.cs'
return (template, content_type)
}}}

--Noah

Ilias Lazaridis

unread,
Sep 15, 2006, 5:49:35 AM9/15/06
to Trac Users
> Sorry, looks like Alec took that bit of hackery out. The way
> ClearSilver looks for templates is by examining each folder in the
> 'hdf.loadpaths' HDF variable. Normally the project templates folder
> and the central templates folder are the first two items in this
> list, with plugin folders being added below that. If you munged this
> list so your folder appears first, you can mask out other templates.
> As a probably much cleaner way to do it, you can just make a request
> filter that does something like this:
> {{{
> def post_process_request(self, req, template, content_type):
> if template == 'wiki.cs':
> template = 'mytemplate.cs'
> return (template, content_type)
> }}}

Yes, this looks much better (although it seems that this would
additional overhead to _every_ request, but ok, it's a tiny one):

http://trac.edgewall.org/browser/trunk/trac/web/api.py#L486

.

Ilias Lazaridis

unread,
Sep 16, 2006, 4:25:55 AM9/16/06
to Trac Users

Noah Kantrowitz wrote:
> Sorry, looks like Alec took that bit of hackery out. The way
> ClearSilver looks for templates is by examining each folder in the
> 'hdf.loadpaths' HDF variable. Normally the project templates folder
> and the central templates folder are the first two items in this
> list, with plugin folders being added below that. If you munged this
> list so your folder appears first, you can mask out other templates.

I understand.

This would have the benefit to work with *.cs includes, too.

But I dislike to change the behaviour, as this could have side-effects
(e.g. on other plugins which work in a tricky way with the hdf).

Any other Idea?

> As a probably much cleaner way to do it, you can just make a request
> filter that does something like this:
> {{{
> def post_process_request(self, req, template, content_type):
> if template == 'wiki.cs':
> template = 'mytemplate.cs'
> return (template, content_type)
> }}}

this one works fine (except with *.cs includes)

.

Noah Kantrowitz

unread,
Sep 16, 2006, 4:49:31 AM9/16/06
to trac-...@googlegroups.com
The "correct" way to do this is as a transform on the XInclude
elements in the Genshi output stream, but thats not yet an option ;-)

--Noah

Ilias Lazaridis

unread,
Sep 16, 2006, 4:58:08 AM9/16/06
to Trac Users
Noah Kantrowitz wrote:
> The "correct" way to do this is as a transform on the XInclude
> elements in the Genshi output stream, but thats not yet an option ;-)

ok, will try with the available stuff and your hints.

thank's a lot!

.

Ilias Lazaridis

unread,
Sep 16, 2006, 7:34:53 AM9/16/06
to Trac Users
Noah Kantrowitz wrote:
> Sorry, looks like Alec took that bit of hackery out. The way
> ClearSilver looks for templates is by examining each folder in the
> 'hdf.loadpaths' HDF variable. Normally the project templates folder
> and the central templates folder are the first two items in this
> list, with plugin folders being added below that. If you munged this
> list so your folder appears first, you can mask out other templates.
...

I'm a little overworked at this point, and start to get confused with
this hdf thing. A little blindness gives the rest.

Is it ok if I munge this hdf.loadpaths within "post_process_request" ?

to the code:


def post_process_request(self, req, template, content_type):

...

loadpaths = <how do I retrieve the actual "load-paths" from within the
hdf>
loadpaths.insert(0, <my-path>
req.hdf = HDFWrapper(loadpaths)

I'm doing something wrong, but as said... blindness!
.

Noah Kantrowitz

unread,
Sep 17, 2006, 2:29:51 AM9/17/06
to trac-...@googlegroups.com
Read the Clearsilver API docs, they should how to walk an HDF using
nextNode() and childNode().

--Noah

Ilias Lazaridis

unread,
Sep 17, 2006, 11:12:16 AM9/17/06
to Trac Users
Noah Kantrowitz wrote:
> On Sep 16, 2006, at 7:34 AM, Ilias Lazaridis wrote:
> > Noah Kantrowitz wrote:
> >> Sorry, looks like Alec took that bit of hackery out. The way
> >> ClearSilver looks for templates is by examining each folder in the
> >> 'hdf.loadpaths' HDF variable. Normally the project templates folder
> >> and the central templates folder are the first two items in this
> >> list, with plugin folders being added below that. If you munged this
> >> list so your folder appears first, you can mask out other templates.
> > ...
> >
> > I'm a little overworked at this point, and start to get confused with
> > this hdf thing. A little blindness gives the rest.
...

> > req.hdf = HDFWrapper(loadpaths)
> >
> > I'm doing something wrong, but as said... blindness!
>
> Read the Clearsilver API docs, they should how to walk an HDF using
> nextNode() and childNode().

I don't like Clearsilver.

(btw: I was overworked, you can see it from my suggestion, which
completely overwrites the hdf).

I have implemented it abstractly:

http://dev.lazaridis.com/base/changeset/48

.

Reply all
Reply to author
Forward
0 new messages