为模板化视图提供与之关联的架构设置。
项目描述
介绍
此包允许您定义一组视图、模式和模板,这些视图、模式和模板可用作 Plone 站点上视图的模板。
因此,基本上,它只允许一种简单的机制来提供附加的附加设置的可重用模板。您为其填写设置的每个模板,然后可以从网站上其他地方的另一个模板视图引用。
基本示例
定义您的设置:
>>> class ICustomSettings(Interface): >>> setting_one = schema.TextLine(title=u'Setting One') >>> setting_two = schema.Text(title=u'Setting Two', default=u'')
定义模板视图实用程序:
>>> from wildcard.templatedviews.browser import BaseViewUtility
>>> from plone.app.form.widgets.wysiwygwidget import WYSIWYGWidget
>>> class CustomTemplateViewUtility(BaseViewUtility):
>>> settings = ICustomSettings
>>> _for = None
>>> title = u'Custom Template'
>>> description = u'a custom template settings.'
>>> custom_widgets = (
>>> ('setting_one', WYSIWYGWidget),
>>> )
并用 zcml 连接起来:
>>> <browser:page >>> for="*" >>> name="custom-template" >>> class="wildcard.templatedviews.browser.BaseView" >>> template="templates/custom-template.pt" >>> permission="zope2.View" >>> /> >>> <utility factory=".CustomTemplateViewUtility" name="custom-template" /> >>> <adapter >>> for="*" >>> provides=".ICustomSettings" >>> factory="wildcard.templatedviews.settings.TemplateViewSettings" >>> />
然后在您的custom-template.pt中,您可以使用如下设置:
>>> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >>> xmlns:tal="http://xml.zope.org/namespaces/tal" >>> xmlns:metal="http://xml.zope.org/namespaces/metal" >>> xmlns:i18n="http://xml.zope.org/namespaces/i18n" >>> lang="en" >>> metal:use-macro="here/main_template/macros/master" >>> i18n:domain="plone"> >>> <body> >>> >>> <metal:main fill-slot="main" tal:define="settings python: view.settings"> >>> <tal:main-macro metal:define-macro="main"> >>> <h1 tal:content="python: settings.setting_one" /> >>> <p tal:content="structure python: settings.setting_two" /> >>> </tal:main-macro> >>> </metal:main> >>> </body> >>> </html>
您还需要将“模板视图”视图添加到您想要使用它的内容类型的可用视图列表中。
现在要在安装后使用它,从显示下拉菜单中选择“模板视图”,然后使用“选择模板”和“模板设置”来自定义您的模板视图。
查看源代码以获取有关如何使用它的更多示例。
变更日志
1.0b4 (2012-08-27)
修复变换的使用
1.0b3 (2012-08-09)
克隆 4.1 兼容
转换 uid
1.0b2 (2011-10-25)
如果遍历对象不起作用,请尝试在重定向存储中查找它
1.0b1 (2011-04-13)
为设置和所选模板提供保存事件
允许对字段进行排序
1.0a2 (2010-04-10)
无法找到实用程序时修复问题
添加更多实用方法以查看
1.0a1 (2011-03-20)
初始发行