开发者

Override Canonical Object in 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 cano开发者_Go百科nical 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?


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 the folder_full_view template.


bda.contentproxy was a product that make this, but be aware... is a very complex task, full of problems behind the corner

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜