Re: Cheetah's #include base directory

"R. Tyler Ballance" <[email protected]> Tue, 29 Dec 2009 10:32:00 -0800
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
On Tue, 29 Dec 2009, Pablo Antonio wrote:

> Hello,
>     this is my first day with Cheetah. I have an old app which uses
> the web.py framework and Cheetah for templating.

Howdy! Sorry I missed you on IRC, we're quite a ways apart as far as time zones
are concerned ;)

> Thing is some files have an '#include "<file>"' at the top. They usually
> include some header with the DOCTYPE and a title and that's pretty much
> it. Well, the problem is this <file> is being searched in the current
> directory the app is located, and not in the ./templates/ dir which is
> where the templates are.

Personally I don't use the #include directive ever (I find it too much like
Smarty (read: hacky)). That said, you *might* be able to override the method on
your base template class `serverSidePath` which is what the #include directive
handler uses to locate the included template. In effect:

    #import os.path
    #def serverSidePath(**kwargs)
        ## serverSidePath takes a `path` keyword arg

        ## Assuming your templates directory is called `templates`
        #return os.path.join(os.getcwd(), 'templates', kwargs['path'))
    #end def

I'm making a couple of assumptions in the code above, namely that `os.getcwd()`
will return the application's base directory. That said, let me know if you
can't get serverSidePath to work for you, I'll be on IRC for the next 8-12
hours while I work so feel free to ping me there :)

> How can I fix this? Is this different in newer versions? I'm using 2.0.1
> (the newest in Ubuntu's repositories).

It's worth noting that v2.4.1 is the latest release
(http://pypi.python.org/pypi/Cheetah/2.4.1)

Cheers,
-R. Tyler Ballance
--------------------------------------
 Jabber: [email protected]
 GitHub: http://github.com/rtyler
Twitter: http://twitter.com/agentdero
   Blog: http://unethicalblogger.com

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (GNU/Linux)

iEYEARECAAYFAks6SyAACgkQFCbH3D9R4W+BRQCggN8GmQApkSkpchn1oor09mqo
TeUAnjmFTuUVYTkTeeBp41JF4fX3QyKO
=Oppt
-----END PGP SIGNATURE-----