【问题标题】:My Archetypes-based content type can't be viewed无法查看我的基于原型的内容类型
【发布时间】:2017-10-05 17:30:30
【问题描述】:

我有一个小的 Plone 扩展,其中包含一个简单的基于 Archetypes 的内容类型(我无法添加 TTW,请参阅 my previous question);项目设置为on GitHub

添加对象后,我在执行plone.abovecontenttitle 内容提供程序期间得到一个KeyError: 'view'

{'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 模式下应该可以轻松重现。

编辑: 我注意到,在“已安装产品”视图 (/portal_quickinstaller/MyCompany.MyProduct/manage_installationInfo) 中,我的产品有 Status: installedTypes MyType,但 Content Type Registry entries 是空的 (None)。

【问题讨论】:

  • 不可重现,正在获取“AttributeError:@@transform”,源自您的视图模板。
  • 抱歉,感谢您的尝试。我删除了transform 部分。
  • @Ida:我将default_immediate_view 属性更改为base_view;现在可以这样查看我的类型。使用(仍然存在的)mytype_view 时,我仍然得到'view' KeyError,不明白原因。也许它与内容提供商有关? (我希望这是可重现的。)

标签: plone plone-4.x archetypes


【解决方案1】:

内容提供者调用适配器,它期望出现view-argument[1] 并且基于皮肤的模板不提供,这与基于浏览器的模板相矛盾。 为了解决这个问题,我们可以像在main_template 中那样使用全局@@plone-var[2],因为@@ploneBrowserView 的一个实例,它提供了视图参数:

tal:define="view context/@@plone;"

这让我觉得,内容提供者使用的适配器应该考虑没有视图可用的情况。

如果您想拥有通常的站点结构并只自定义内容部分,您还可以将模板填充到内容槽中,然后继承 main_template 中的所有内容,以及 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”,因为项目的工作流状态正在处理这个问题,并且会评估当前语言等内容。

如果您只想自定义内容项的正文部分,请将content 更改为content-core,然后无论如何都会呈现通常的内容提供程序,您不需要插入它们,如果您希望它们按通常的顺序排列。

[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

【讨论】:

  • 非常感谢!我将最小可能的解决方案推送到 GibHub 存储库。
猜你喜欢
  • 1970-01-01
  • 2014-12-07
  • 1970-01-01
  • 1970-01-01
  • 2010-10-23
  • 2018-07-12
  • 2018-12-11
  • 2021-01-04
相关资源
最近更新 更多