覆盖 Plone 中的规范对象
我想渲染一个对象的视图来代替另一个对象,但保留最初遍历的规范路径,因此面包屑和对象选项卡等仍然表现相同。
我知道如何渲染另一个对象来代替规范对象,但似乎几乎不可能覆盖用于规范对象的对象,除非我可能覆盖“plone_context_state”浏览器视图中的“canonical_object”方法。
下面是我的视图 call 方法来渲染另一个对象的代码:
item = aq_base(default_item).__of__(self.context)
layout = item.getLayout() or item.getDefaultLayout()
try:
return aq_acquire(item, layout)(*args, **kwargs)
except AttributeError:
try:
return getMultiAdapter((item, self.request), name=layout)(*args, **kwargs)
except: pass
return super(DefaultItemEnabledView, self).__call__(*args, **kwargs)
现在,是否可以使 plone 所使用的规范对象成为最初遍历的对象,以便适当地应用面包屑、对象选项卡等?
I'd like to render an object's view in place of another object and yet keep the canonical path as the one originally traversed to so breadcrumbs and object tabs, etc all still act the same.
I know how to render the other object in place of the canonical one, but it almost seems impossible to override what is used for the canonical object unless I perhaps override the "canonical_object" method in the "plone_context_state" browser view.
Here is the code I have my view call method for rendering the other object:
item = aq_base(default_item).__of__(self.context)
layout = item.getLayout() or item.getDefaultLayout()
try:
return aq_acquire(item, layout)(*args, **kwargs)
except AttributeError:
try:
return getMultiAdapter((item, self.request), name=layout)(*args, **kwargs)
except: pass
return super(DefaultItemEnabledView, self).__call__(*args, **kwargs)
Now, is it possible to make the canonical object used by plone the originally traversed one so breadcrumbs, object tabs, etc are applied appropriately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要的恐怕是不可能完成的任务;您正在为新的上下文渲染完整的镶边,因此所有内容都将使用该上下文进行渲染。你必须重做一切;面包屑、操作、portlet、任何其他上下文相关的视图。
我不确定您的用例是什么,您必须支持任意对象的所有可能的布局,您可能必须在这里重新考虑您的选择。
如果您没有需要所有可能的布局才能工作的用例,那么您可以为规范对象创建一个自定义视图,该视图只是为其他对象重新渲染内容。例如,许多内容视图已经包含可以重复使用的宏。查看
skins/plone_content/folder_full_view_item.pt
示例模板,该模板重用此类宏来呈现folder_full_view
模板文件夹中的项目。I am afraid that what you want is an impossible task; you are rendering the full chrome for a new context and everything will thus render using that context. You'd have to redo everything; breadcrumbs, actions, portlets, any other context-sensitive viewlets.
I am not sure what your use-case is that you have to support all possible layouts of arbitrary objects, you may have to rethink your options here.
If you do not have a use-case that requires all possible layouts to work, then you can just create a custom view for your canonical object that just re-renders the content well for the other object. Many views for content already include macros you can re-use, for example. Take a look at
skins/plone_content/folder_full_view_item.pt
for an example template that reuses such macros to render items in a folder for thefolder_full_view
template.bda.contentproxy 是一个实现这一点的产品,但是注意...是一项非常复杂的任务,背后充满了问题
bda.contentproxy was a product that make this, but be aware... is a very complex task, full of problems behind the corner