{"id":10373,"library":"zope-tal","title":"Zope Template Application Language (TAL)","description":"zope.tal provides an implementation of the Zope Template Application Language (TAL), a powerful and secure server-side templating system primarily used within the Zope framework but usable standalone. It enforces strict separation of presentation logic from application logic. The current stable version is 6.0, with releases typically tied to Python version support updates and Zope ecosystem advancements.","status":"active","version":"6.0","language":"en","source_language":"en","source_url":"https://github.com/zopefoundation/zope.tal","tags":["templating","zope","tal","html","xml","server-side"],"install":[{"cmd":"pip install zope.tal","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for Zope component architecture, required >= 6.0 for zope.tal 6.x.","package":"zope.interface","optional":false},{"reason":"Build-time dependency, implicitly handled by pip.","package":"setuptools","optional":false}],"imports":[{"note":"The `zope.app.tal` package was moved to `zope.tal` in older versions. Modern code uses `zope.tal` directly.","wrong":"from zope.app.tal.template import TALTemplate","symbol":"TALTemplate","correct":"from zope.tal.template import TALTemplate"},{"note":"Used for direct parsing of HTML-like TAL templates.","symbol":"HTMLTALParser","correct":"from zope.tal.htmltalparser import HTMLTALParser"}],"quickstart":{"code":"from zope.tal.template import TALTemplate\n\n# Define a simple TAL template\ntemplate_string = '''\n<html tal:define=\"user_name context/name\">\n  <head>\n    <title tal:content=\"context/page_title\">Default Title</title>\n  </head>\n  <body>\n    <h1 tal:content=\"string:Hello, ${user_name}!\" />\n    <p tal:condition=\"context/is_admin\">Welcome, Administrator!</p>\n    <ul tal:repeat=\"item context/items\">\n      <li tal:content=\"item\" />\n    </ul>\n  </body>\n</html>\n'''\n\n# Create a context object with data for the template\nclass MyContext:\n    def __init__(self, name, title, admin_status, item_list):\n        self.name = name\n        self.page_title = title\n        self.is_admin = admin_status\n        self.items = item_list\n\n# Instantiate the template\ntemplate = TALTemplate(template_string)\n\n# Create a context instance\ncontext_data = MyContext(\n    name='Alice',\n    title='My TAL Page',\n    admin_status=True,\n    item_list=['Item 1', 'Item 2', 'Item 3']\n)\n\n# Render the template with the context\noutput = template(context_data)\n\nprint(output)","lang":"python","description":"This quickstart demonstrates how to define a TAL template, create a Python object to serve as the template context, and render the template using `TALTemplate`."},"warnings":[{"fix":"Ensure your project uses Python 3.9 or newer. Upgrade your Python environment if necessary.","message":"Python 3.8 and older are no longer supported by `zope.tal` version 6.x.","severity":"breaking","affected_versions":"6.0+"},{"fix":"Upgrade `zope.interface` in your environment: `pip install 'zope.interface>=6.0'`.","message":"The `zope.interface` dependency has been updated, requiring `zope.interface >= 6.0`.","severity":"breaking","affected_versions":"6.0+"},{"fix":"Always ensure your TAL templates are valid XML/HTML. Use an HTML linter or validator if you encounter parsing issues.","message":"TAL templates are strict about XML/HTML well-formedness. Mismatched tags, unquoted attributes, or special characters not escaped can lead to parsing errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Carefully verify that all variables and paths referenced in your TAL template exist in the provided context object. Use `tal:condition` or `tal:default` to handle potentially missing values gracefully.","message":"Context path expressions (e.g., `context/title`) are case-sensitive and require attributes/items to exist on the context object or its sub-objects. Non-existent paths will lead to `AttributeError` or `KeyError` during rendering.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Update your import statements to use `from zope.tal.template import TALTemplate` (or other relevant symbols from `zope.tal`).","cause":"Attempting to import from an old package path (`zope.app.tal`) which was deprecated and removed in favor of `zope.tal` directly.","error":"ModuleNotFoundError: No module named 'zope.app.tal'"},{"fix":"Review your template string for well-formedness. Ensure all tags are properly closed, attributes are quoted, and HTML entities are correctly escaped.","cause":"The TAL template contains malformed XML/HTML, such as unclosed tags, incorrect nesting, or invalid characters.","error":"xml.etree.ElementTree.ParseError: junk after document element:"},{"fix":"Ensure that the context object passed to the `TALTemplate` instance has all the attributes or dictionary keys that the template attempts to access. Debug by inspecting the `context` object at runtime.","cause":"A TAL path expression (e.g., `context/missing_attribute`) references an attribute that does not exist on the provided context object.","error":"AttributeError: 'MyContext' object has no attribute 'missing_attribute'"}]}