Satheesh Babu
2001/04/11
If you use Zope for managing your site's content, chances are that you use DTML Templates heavily. This explains how you can make relative links to common elements used in headers and footers.
Typically, your DTML Document has the structure
standard_html_header
Content
standard_html_footer
The standard_html_header and standard_html_footer are DTML methods you define
in Zope to get you a consistent look through-out the site.In your header, let us
say you have a logo image, some navigation links etc. Let us focus on how can
we link to your logo image, stored as ZopeRoot/images/mylogo.gif
.
Usually what you can do is to make these references absolute with the fully qualified URLs. If you use different servers for development and production, fully qualified URLs are not ideal - well, absolute links are not ideal in any case.
http://www.myproductionsite.com/images/mylogo.gif
http://www.myproductionsite.com/
in
the production server, and http://www.mydevelopment.com/
in the
development server.
<dtml-var siteroot>images/mylogo.gif
instead of http://www.myproductionsite.com/images/mylogo.gif
. Now,
when you are in production server, Zope serves up the HTML with that server
name and when you are in the development server, Zope serves the HTML with the
development server name.
BASE0
.
So, you can change your siteroot method to have <dtml-var BASE0>
.
That should work in any Zope server.
The second best thing to relative URLs is where you don't specify the server name, but make all your links with respect to root of the domain (/). This will require reworking if your root URL canges.
/images/mylogo.gif
www.bigbadtakeover.com/myproductionsite/
?
You will have to and change the reference like
/myproductionsite/images/mylogo.gif
http://www.bigbadtakeover.com/myproductionsite/
Now for the ideal situation. If you have followed the siteroot method
above, edit it so that the code is the one below.
Test it out by browsing to these URLs in your Zope installation.
<dtml-in "PARENTS[1:]">../</dtml-in>
../
../../../
How is that? So, whereever you call siteroot from, you get the relative
path! Every Zope object (other than the root) has a parent object. This hierarchy
is stored in the PARENTS array. So, all you are doing here is going up the
PARENTS hierarchy, and for every parent print ../
. Since we don't need the
current folder, we start from the second item in the array, by calling it
as PARENTS[1:]
instead of PARENTS[]
.
Let us say the bidbadtakeover.com forces you to move your site one level
below. How do you modify your siteroot
? First, you need to
move over everything to a subfolder. Then you can use PARENTS[2:] as the
array, in the code.
Since you are seeing this, it means that your browser does not support cascading style sheets. Please download and use one of the many browsers that support web standards.