Re: How do I reference functions from another template?

"R. Tyler Ballance" <[email protected]>
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
On Mon, May 04, 2009 at 09:34:03PM -0400, Saul Jaspan wrote:
> Lets say I have a template, dir1/dir2/dir3/foo.tmpl:
> 
> #def FooFunct($param1, $param2):
>   Stuff here
> #end def
> 
> and another template where I want to call FooFunct, dir1/base.tmpl:
> 
> #include "dir1/dir2/dir3/foo.tmpl"
> #* Want to call $FooFunct("1", "2") *#


Tavis and I have talked about starting to try to phase out the "#include"
statement so I wouldn't exactly recommend it if you can avoid it.

What it sounds like you need is an addition to Cheetah I just released,
proper @staticmethod and @classmethod support. Basically with
@staticmethod support you would have syntax like this:


dir1/dir2/dir3/foo.tmpl
=================================
#@staticmethod
#def FooFunct($param1, $param2):
   #return ($param1, $param2)
#end def


dir1/base.tmpl
=================================
#from dir1.dir2.dir3 import foo

$foo.FooFunct('omg', 'rly?')



The import and calling syntaxes mirror that of Python static methods
themselves in this case as well.

You can find @staticmethod and @classmethod support in v2.1.2 which I'm
preparing for release today (it's already been tagged)
	http://github.com/rtyler/cheetah/tarball/v2.1.2


> I assume I need to import foo in some way but don't know where it
> lives (I have tried from dir1.dir2.dir3 import foo already ;).  Is
> there a way of doing this without first compiling foo.tmpl?

If you really *must* avoid first compiling foo.tmpl, then for now the
#include would be what you'd want. See:
	http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000860000000000000000


Cheers
-- 
-R. Tyler Ballance
Slide, Inc.

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com

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

iEYEARECAAYFAkoAakoACgkQFCbH3D9R4W+QqQCgpfpYsZWa6WRCrL39pDvmxMiD
xRYAnRk4ZTztDuD6L5jMfkl+dfnBK2oa
=dHOF
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.