Re: [Templates] relative paths vs absolute
[prev]
[thread]
[next]
[Date index for 2005/06/01]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
This is great! Just what I was looking for.<br>
<br>
Except, I need to know where the one-liner goes. (Sorry, I'm new to
this, and don't understand it all yet.)<br>
<br>
THanks for your help,<br>
Steve<br>
<br>
Andy Wardley said the following on 6/1/2005 11:37 AM:
<blockquote cite="mid20050601183733.GN41078@xxxxxxx.xxx" type="cite">
<pre wrap="">Steve Kelem wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Is there a way to get TT to generate relative paths in the links instead
of absolute ones?
</pre>
</blockquote>
<pre wrap=""><!---->
Yep, you just need to figure out how many '..'s you need to get back to
the root of the web site, then use that as a root url which is prefixed
onto all the URLs you use.
Here's the one-liner:
rooturl = template.name.replace('\w+\.\w+$', '').replace('\w+', '..')
Included below is the more complete version with comments and debugging
messages. This is my lib/config/root template which gets called early
on in the pre-process phase. It allows you to pre-define a rooturl
variable (when you have an absolute root you want to use). If you
don't define it, then it generates the relative one.
[% # This configuration template determines the URL for the root
# of the web site from the current page template.
#
# The 'rooturl' value can be hard-coded to a particular value
# (e.g. <a class="moz-txt-link-freetext"
href="http://example.wardley.org/">http://example.wardley.org/</a>) in the etc/ttree.cfg
# configuration file. Otherwise we generate a relative path to
# the root (e.g. ../../) based on the location of the current page
# template.
#
# For example, if the current template is "foo/bar/baz.html"
# then we strip off the last part of the path which indicates
# the file name, "baz.html" to leave "foo/bar/". Then we convert
# each remaining part of the path to '..', resulting in '../../'
# This rooturl variable can then be prefixed to any sitewide url
# to get the correct path. For example, "${rooturl}images/foo.gif"
# becomes "../../images/foo.gif"
IF rooturl;
IF debug.sitemap;
" # using hard-coded rooturl: $rooturl\n" | stderr;
END;
ELSE;
rooturl = template.name;
rooturl = rooturl.replace('\w+\.\w+$', '');
rooturl = rooturl.replace('\w+', '..');
IF debug.sitemap;
" # relative rooturl for $template.name is $rooturl\n" | stderr;
END;
END;
-%]
HTH
A</pre>
</blockquote>
</body>
</html>
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
 |
Re: [Templates] relative paths vs absolute
Steve Kelem 23:41 on 01 Jun 2005
|