logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Relative file actions?: msg#00048

Subject: Re: Relative file actions?
spm-twExxoGTpbzV8l1SNXPPS7pzq4S04n8Q@xxxxxxxxxxxxxxxx wrote:
> As it transpires, I appear to have discovered the answer in any event. Not
> sure how I missed it. Sigh.

Easily done.  And as it happens, there are many different ways to skin
this particular cat...

Here's an extract of a typical 'config' pre-process template that I use.  
I can either set an explicit 'rooturl' variable, either by hard-coding 
it in this template, or setting it somewhere else (e.g. ttree --define
rooturl=whatever command line option).  Or if rooturl is not defined,
it uses the current template path (e.g. 1/2/3.html) to figure out the
relative path to the root (e.g. ../..)

[%  #------------------------------------------------------------
    # rooturl
    #   This defines the root of the document tree.  It can be 
    #   set by uncommenting the line below or in the etc/ttree.cfg
    #   file by including a line like this:
    #      define rooturl = /~abw/tt3/
    #   Certain URLs (e.g. for the CSS file and images directory)
    #   are constructed relative to this root. e.g. 
    #      "${rooturl}tt3.css"  => /~abw/tt3/tt3.css"
    #      "${rooturl}images"   => /~abw/tt3/images"
    #   These will work correctly for pages in any sub-directory.
    #   Alternately, the rooturl variable can be left undefined.
    #   In which case, a relative path is constructed from the 
    #   document location to the root.  For example, the page
    #   "foo/bar/baz.html" has a root of "../../", e.g.
    #      "${rooturl}tt3.css"  => ../../tt3.css"
    #      "${rooturl}images"   => ../../images"
    #------------------------------------------------------------
    
    # uncomment next line to set specific rooturl, or define it
    # elsewhere, or leave it undefined for relative URLs

    #   rooturl = '/root/url/to/site/'

    IF rooturl.length;    # absolute root URL
        # ensure rooturl is '/' terminated
        SET rooturl = "${rooturl}/" 
          UNLESS rooturl.match('\/$');
    ELSE;                 # relative root URL
        # remove filename
        filepath = template.name.replace('\w+\.\w+', '');
        # convert remaining path elements to '..'
        rooturl  = filepath.replace('\w+', '..');
    END;

    # define 'site' data structure
    site = {
        title = 'Template Toolkit Version 3'
    }

    # define url's relative to rooturl
    site.url = {
        root   = rooturl
        home   = "${rooturl}index.html"
        images = "${rooturl}images"
        css    = "${rooturl}tt3.css"
    }

    # ...etc...
-%]


HTH
A


<Prev in Thread] Current Thread [Next in Thread>