Re: #def woes
"R. Tyler Ballance" <[email protected]>
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
On Thu, May 21, 2009 at 02:55:50PM -0700, [email protected] wrote: > #set $faa = self.foo > > This is cool calling with self. doesnt autocall It doesn't call because you're in the right hand operand (where you need not use Cheetah syntax), and you're not using the '$'. When you use the $, that invokes the NameMapper which is responsible for autocalling. I personally prefer this option to $getVar() which feels distinctly non-Pythonic ;) > On 5/20/09, Michael Higgins <[email protected]> wrote: > > On May 20, 2009, at 4:18 PM, R. Tyler Ballance wrote: > > I /think/ this should work: > #set $faa = foo > > I'm not running the latest and greatest, but that doesn't work for me. > What *does* work for me is saying > > #set $faa = self.foo > > Exploiting self in such an unvarnished way seems like it might be too > close to relying on an implementation detail, but maybe it's okay. I > guess Cheetah already has to guarantee not to do name-mangling or > something so that Python code can call Cheetah methods properly... > > Alternatively, you can use: > #set $faa = $foo > > If you compile the templates with autocalling disabled > > Personally, I'm not a huge fan of tweaking the compile settings a lot > for different templates. It's just one more thing that can mysteriously > break and take a long time to figure out. > > To answer mobiledreamer's (later) question about what a wrapper function > would look like: > > ## return a callable value for $name > #def F($name) > #return $getVar($name, autoCall=False) > #end def > > #set $faa = $F('foo') > > ... assuming the self trick isn't the preferable style. (It's certainly > shorter!) > > Mike > > -- > Bidegg worlds best auction site > http://bidegg.com -- -R. Tyler Ballance Slide, Inc. ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.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) iEYEARECAAYFAkoVzloACgkQFCbH3D9R4W+tfwCgqHhX222qajk7fsrnj8HPr2v+ /jQAoINndVyBDu/V+qsWMxKqRK4mIxUa =iEXN -----END PGP SIGNATURE-----