我的基于原型的内容类型无法查看 [英] My Archetypes-based content type can't be viewed
问题描述
我有一个小的Plone扩展,其中包含一个简单的基于原型的内容类型(与我以前无法添加TTW的内容类型相同,请参见在GitHub上.
I have a little Plone extension which contains a simple Archetypes-based content type (the same which I had not been able to add TTW, see my previous question); the project setup is on GitHub.
添加对象后,在执行plone.abovecontenttitle
内容提供程序的过程中得到一个KeyError: 'view'
:
After adding an object, I get a KeyError: 'view'
during execution of the plone.abovecontenttitle
content provider:
{'container': <MyType at /plone/test-for-new-types/a-mytype-object>,
'context': <MyType at /plone/test-for-new-types/a-mytype-object>,
'default': <object object at 0x7fc4f8ebe520>,
'here': <MyType at /plone/test-for-new-types/a-mytype-object>,
'loop': {},
'nothing': None,
'options': {'args': ()},
'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x7fc4c9484db8>,
'request': <HTTPRequest, URL=https://my.testing.site/test-for-new-types/a-mytype-object/mytype_view>,
'root': <Application at >,
'template': <FSPageTemplate at /plone/test-for-new-types/a-mytype-object/mytype_view>,
'traverse_subpath': [],
'user': <PloneUser 'me'>}
在develop
模式下安装我的小扩展程序,应该可以轻松重现.
It should be reproducible easily with my little extension installed in develop
mode.
修改:
我注意到,在已安装产品"视图(/portal_quickinstaller/MyCompany.MyProduct/manage_installationInfo
)中,我的产品具有Status: installed
和Types MyType
,但是Content Type Registry entries
为空(None
).
I noticed that, in the "Installed Product" view (/portal_quickinstaller/MyCompany.MyProduct/manage_installationInfo
), my product has Status: installed
and Types MyType
, but Content Type Registry entries
is empty (None
).
推荐答案
内容提供者调用适配器,该适配器期望出现view
参数,并且不提供基于皮肤的模板,这与基于浏览器的模板.
为了解决这个问题,我们可以像在main_template
中一样使用全局@@plone
-var [2],因为@@plone
是BrowserView
的实例,它提供了视图参数:
Content-providers call adapters, which expect a view
-argument to be present[1] and skin-based templates don't provide, in contradiction to browser-based templates.
To fix that, we can use the global @@plone
-var[2] like it's done in main_template
, because @@plone
is an instance of BrowserView
, it provides the view-argument:
tal:define="view context/@@plone;"
这让我觉得,内容提供者正在使用的适配器应该考虑没有可用视图的情况.
Which makes me think, the adapters the content-providers are using, should regard the case that no view is available.
如果您希望拥有通常的网站结构并仅自定义内容部分,则还可以将模板填充到内容槽中,然后main_template的所有内容都将被继承,并且view-var也将被继承:
In case you want to have the usual site-structure and just customize the content-part, you could also fill your template into the content-slot, then everything from main_template is inherited, also the view-var:
<metal:main metal:use-macro="context/main_template/macros/master">
<metal:content fill-slot="content">
Hey, a working content-provider:
<div tal:replace="structure provider:plone.abovecontenttitle" />
Oh, so much more much, here...
</metal:content>
</metal:main>
我建议这样做,因为那样您就不必担心在标头部分中做的一切正确了.例如.不必使用"raiseAnon",因为该项目的工作流状态正在处理该问题,并且将评估当前语言等内容.
Which I would recommend, because then you don't need to worry about doing everything right in the header-part. E.g. using "raiseAnon" shouldn't be necessary, because the item's workflow-state is taking care of that and things like the current language will be evaluated, etc.
如果您只想自定义内容项的正文部分,将content
更改为content-core
,则通常将显示内容提供者,那么无论如何您都不需要插入它们要他们按通常的顺序.
If you only want to customize the body-part of the content-item, change content
to content-core
, the usual content-providers will be rendered then anyways, you don't need to insert them, if you want them in the usual order.
[1] https://docs. plone.org/4/en/old-reference-manuals/portlets/rendered.html
[2] https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/browser/ploneview.py
这篇关于我的基于原型的内容类型无法查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!