Reputation: 2527
I am using Cheetah template together with Cherrypy, below is my main python file
Main.py:
def multiple(a,b):
return a*b
def index(self):
t = Template('template.tmpl')
#blah implementation here
In my template file, I wish to achieve
<body>
<div>
$multiple(2,3)
</div>
</body>
Anyone has an idea how can I get this implement? Many thanks.
Regards, Andy.
Upvotes: 1
Views: 1241
Reputation: 94602
Why not just import Main in the template?
#from Main import multiple
<body>
<div>
$multiple(2,3)
</div>
</body>
Upvotes: 0
Reputation: 11
This may answer it:
import Cheetah
import Cheetah.Template
def multiple(a,b):
return a*b
print Cheetah.Template.Template(file='template.tmpl',
searchList=[dict(multiple=multiple)])
Upvotes: 1
Reputation: 32240
t = Template("template.tmpl")
t.multiple = multiple
That should do the trick.
Upvotes: 3
Reputation: 80791
try with the searchList argument :
def index(self):
t = Template('template.tmpl', searchList=[multiple])
It allows you to define "placeholders" that you will be able to use in template definition.
Upvotes: 2