How to override template “folder_full_view_item.pt” only for a Custom Type?

試著忘記壹切 提交于 2019-12-05 19:26:24

Instead of overriding folder_full_view_item.pt you should rather create your own custom default template for your Content Type MyType.

Try using tal:condition="python:item_type=='MyType'" and item_type!='MyType' for different display needs. Hope this helpful.

To override this template you will need 2 things: a browser layer and the view that is going to be used in the context of your content type.

First, declare the browser layer:

from zope.interface import Interface

class IMyLayer(Interface):
    """A layer specific for this add-on product.
    """

This browser layer needs to be installed with your content type. Create a browserlayer.xml file with the following:

<?xml version="1.0"?>
<layers>
  <layer name="my.type" interface="my.type.interfaces.IMyLayer" />
</layers>

Then, the view will be active when you are in the context of your content type and when your browser layer is active:

from five import grok

class FolderFullViewItem(grok.View):
    """Override folder_full_view_item for MyType.
    """
    grok.context(IMyType)
    grok.layer(IMyLayer)
    grok.name('folder_full_view_item')
    grok.template('folder_full_view_item')
    grok.require('zope2.View')

On sc.blog we have a similar use case on which we override folder_summary_view and folder_full_view, take a look on it.

Also, don't forget to read the Layers chapter on the Plone Developers Documentation.

As the skins-tool seems to be deprecated and probably performance-losses would be involved, I'd rather go with a dedicated browser-view for your custom-contenttype, too, but to answer the question:

You can use collective.editskinswitcher (thanks to M. v. Rees!), without rewriting too much and even getting some nice and easy to configure dev-features along the way (visitors-view, while actually logged-in, via URL-distinction, e.g.).

In this case, we take advantage of the possibility to set the skin-property on a folderish contenttype-object and roughly, these steps should make the deal:

  • Place the customized folder_full_view_item.pt -template in any of your theme's skin-folders.

  • On creation of your contenttype, add an event-listener, which sets the freshly born object's skin_name to your theme's skin-name (have a look at c.editskinswitcher for methods and props, the referring HTTP-request is @@switchDefaultSkin?skin_name=YourTheme, btw).

  • Set another theme-skin as the global default for all other contextes in portal_skins-properties.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!