{"id":27567,"library":"zope-contentprovider","title":"zope.contentprovider","description":"Content Provider Framework for Zope Templates. Provides a mechanism for registering and rendering pluggable content providers (widgets, portlets) in Zope Page Templates. Current version: 7.0, released 2024-07-18. Release cadence: ad-hoc, based on Zope Toolkit releases.","status":"active","version":"7.0","language":"python","source_language":"en","source_url":"https://github.com/zopefoundation/zope.contentprovider","tags":["zope","template","content provider","component architecture"],"install":[{"cmd":"pip install zope.contentprovider","lang":"bash","label":"Install the package from PyPI"}],"dependencies":[{"reason":"Required for interface definitions (IContentProvider, IContentProviderFactory).","package":"zope.interface","optional":false},{"reason":"Required for component architecture and adapter registration.","package":"zope.component","optional":false},{"reason":"Required for request/response handling and browser page support.","package":"zope.publisher","optional":true},{"reason":"Used for template-based content provider lookups.","package":"zope.traversing","optional":true}],"imports":[{"note":"Incorrect import path; interface is in the 'interfaces' submodule.","wrong":"from zope.contentprovider import IContentProvider","symbol":"IContentProvider","correct":"from zope.contentprovider.interfaces import IContentProvider"},{"note":"Class is in the 'provider' submodule, not in top-level package.","wrong":"from zope.contentprovider import ContentProviderBase","symbol":"ContentProviderBase","correct":"from zope.contentprovider.provider import ContentProviderBase"},{"note":"The expression class is named TALESContentProvider, not TALESContentProviderExpr.","wrong":"from zope.contentprovider.tales import TALESContentProviderExpr","symbol":"TALESContentProvider","correct":"from zope.contentprovider.tales import TALESContentProvider"}],"quickstart":{"code":"from zope.interface import implementer\nfrom zope.contentprovider.interfaces import IContentProvider\nfrom zope.contentprovider.provider import ContentProviderBase\n\n@implementer(IContentProvider)\nclass MyProvider(ContentProviderBase):\n    def __init__(self, context, request, view):\n        super().__init__(context, request, view)\n    def render(self):\n        return '<p>Hello from MyProvider</p>'","lang":"python","description":"Minimal content provider implementation. Extend ContentProviderBase and implement render()."},"warnings":[{"fix":"Upgrade to Python >=3.9 and adjust imports: replace 'zope.contentprovider.browser' with 'zope.contentprovider.provider'.","message":"In version 7.0, removed support for Python 2 and Python < 3.9. Also dropped 'zope.contentprovider.browser' module (merged functionality into 'provider').","severity":"breaking","affected_versions":">=7.0"},{"fix":"Use zope.component's provideAdapter or provideUtility to register providers programmatically.","message":"Global content provider registration via ZCML directive (<browser:contentProvider />) is deprecated in favor of Python-based registration using zope.component.","severity":"deprecated","affected_versions":">=6.0"},{"fix":"Ensure render() always returns a string: return '' or str() if no content.","message":"ContentProviderBase.render() must return a unicode string (or bytes in Python 3). Returning None or non-string objects will cause template rendering errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Register your provider with zope.component.provideUtility(provider, IContentProvider) before template rendering.","message":"When using TALESContentProvider expression in Page Templates, the expression engine expects the provider to be registered as a utility. Unregistered providers silently return empty string.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from zope.contentprovider.interfaces import IContentProvider","cause":"Incorrect import path; IContentProvider is in the 'interfaces' submodule.","error":"ImportError: cannot import name 'IContentProvider' from 'zope.contentprovider'"},{"fix":"Add a render() method that returns a string.","cause":"Missing implementation of render() method.","error":"TypeError: Can't instantiate abstract class MyProvider with abstract methods render"},{"fix":"Remove duplicate ZCML directives or register only once.","cause":"Duplicate registration of the same provider via ZCML.","error":"zope.configuration.config.ConfigurationConflictError: Conflicting configuration for 'contentProvider'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}