Is it it possible to get the names of the variables in a Mako Template before rendering?
from mako.template import Template
bar = Template("${foo}")
# something like:
# >> print bar.fields()
# ['foo']
Use case:
We have configuration files whereby we specify the metadata from the database to be displayed on a webpage. The client can pick one of a few hundred different pieces of named metadata. There are N slots the client can configure but we don't know in advance which pieces of metadata a particular client would like to have filled in on the form. Because if this when rendering the form we need to know, in advance, what variable names we need to pass for this clients template.
We had thought of having a consistent dictionary with all possible values and passing that in each time but it was unworkable as new available fields are added frequently to the underlying pool of available metadata the client could pick.
Because of this we had hoped to use Mako to template the config files but I can't figure out how to determine with the field values in the template would be so that I can build a full-formed Context to pass to the template.