I wrote a plugin where I link some images from the plugin's htdocs folder. To do this, I use the path /chrome/pluginname/...
. When I tested the plugin on another server, where multiple projects are installed (on my dev computer I have only a single Trac project), it didn't work, because the project name was part of the URL, but the htdocs path was appended after the port.
The following URLs worked on the respective server to find the image file:
On my dev computer: <ip>:<port>/chrome/pluginname/...
On the Apache test server: <ip>:<port>/projectname/chrome/pluginname/...
/chrome/pluginname/...
is appended after the port, not after the projectname, so it can't find the files. The resulting URL is <ip>:<port>/chrome/pluginname/...
, like on my dev pc.
How can I dynamically include the projectname in the URL to avoid hardcoding it, or instead make the relative /chrome/pluginname/...
path start after the project name?
In Python code, generate the URL using req.href.chrome('pluginname/...')
. In template code, use ${href.chrome('pluginname/...')}
.
If you need to serve dynamically-generated CSS you have a few options. If you are writing your own page you could put the CSS in a <style>
block of the HTML page, using Genshi variables in the CSS. If you are trying to modify the styling of pages that exist in Trac it becomes much more complicated. The best approach I've seen is to implement IRequestHandler
to serve requests for the stylesheet. You can see this implemented in WikiExtrasPlugin. See changeset 14311 and ticket #11041.