ZPT Variable Namespaces

Status: IsRejectedProposal

Author

JimFulton

Problem

ZPT provides an explicit mechanism for managing variable names in templates using a flat namespace names.

Sometimes, we need more control over names. For example, a macro might want to define names that can be used by callers of a macro to customize a macro's behavior. In TALESAdapters?, we'd like to be able to use an adapters namespace to be able to hold adapter definitions.

Proposal

Add the ability to qualify names with a namespace prefix. A namespace-qualified name would be of the form:

    namespace:name

So, you could define an name in a namespace:

    tal:define="foo:bar"

and use it like any other name:

    tal:content="foo:bar/baz/blah"

We will also define a top-level name namespaces that can be traversed to get a namespace. This is mainly to allow namespace-qualified names to be accessed in Python and other scripting-language expressions:

    tal:content="python: namespaces['foo'].bar"

Issues

Should we require people to declare namespaces before they use them? A possible syntax would be:

    tal:namespace="foo"

Pros:

  • Can catch namespace spelling error at the time of variable definition

Cons:

  • People would have to declare namespaces before they use them. Perhaps this is too much ceremony for ZPT?
  • We'd have to invent and document new machinery. Given scarcity of resources, this is a significant issue.



( 97 subscribers )