Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > cheetah templating: place holders needed in a template

Reply
Thread Tools

cheetah templating: place holders needed in a template

 
 
ajay.padala@gmail.com
Guest
Posts: n/a
 
      04-12-2006
Hi

I would like to be able to get the inputs that are needed into a
template file programmatically.

For example if we had a template:

=====================
$name has $num marbles in his hand.
=====================

I want to be able to initialise this template and call a method on it
to get the list ['name', 'num']

Is there anything in cheetah which does this?

At present, I am sending a "fake" dictionary into the searchList to do
this. This is coded as.

fake = Generic()
t = Template(file=absFileName, searchList=[fake])
print fake.calledAtts

=========================================

class Generic(object):
""" Generic object can pretend to be a dictionary or a list and
doesn't throw
any errors whatever you call it for """

# def __new__(cls, *args, **kwargs):
# if '_inst' not in vars(cls):
# cls._inst = object.__new__(cls, *args, **kwargs)
# return cls._inst

calledAtts = sets.Set()

def __init__(self, *args, **kwargs):
pass

def __call__(self, *args, **kwargs):
return self

def __repr__(self):
return "Generic"

def __nonzero__(self):
return True

def __getattr__(self, name):
return self

__delattr__ = __getattr__

def __setattr__(self, name, value):
return self

def __len__(self):
return 1

def __iter__(self):
return iter(("Generic",))

def __getitem__(self, i):
if isinstance(i,types.StringType):
self.calledAtts.add(str(i))
return self

def __setitem__(self, i, v):
return self

def __contains__(self, itemName):
print "contains " + itemName
return True

def has_key(self, *args, **kwargs):
# print "has key called"
return True

__delitem__ = __getitem__

========================================

This just logs each access to the dictionary and stores the key under
self.calledAtts

But obviously this won't work if I have #if statements etc. I am hoping
cheetah already has this feature somewhere which is much more robust
but I can't find it.

Ajay

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form field place holders in strings Andy B ASP .Net 0 06-15-2008 10:44 AM
Compile Cheetah Template on Windows brianrpsgt1 Python 3 11-30-2007 05:00 AM
cheetah - how do i use .refreshcaceh() in cheetah a Python 0 06-29-2006 04:02 AM
Cheetah template driven object output? Pythonically? Fried Egg Python 1 01-30-2006 03:16 PM
Place holders ASP .Net 1 11-13-2003 08:02 PM



Advertisments