是否可以通过Zope 3浏览器覆盖CMF皮肤中的模板:页面?

时间:2010-12-14 14:37:52

标签: plone zope

我尝试使用具有相同<browser:page ...属性的name=覆盖CMF外观图层提供的视图。这在Plone中是否可行,或浏览器视图是否只能覆盖其他浏览器视图?

3 个答案:

答案 0 :(得分:5)

(这有点晚了,但到底是什么意思)

CMF外观层覆盖浏览器视图。这就是为什么你必须将@@放在URL中浏览器视图名称的前面,即消除它的歧义,并确保调用browserview而不是CMF皮肤层模板。

简而言之,如果您将@@放在前面,浏览器视图将覆盖,否则不会。

即:

localhost:8080/Plone/@@myview 

替代:

localhost:8080/Plone/myview

要解决此问题,请覆盖CMF外观图层中的模板,并tal:define View变量指向@@myview。然后,您仍然可以从CMF外观层模板访问BrowserViews方法。

答案 1 :(得分:3)

默认情况下,CMF外观机制在查找视图之前会在portal_skins中查找。您可以通过自定义IPublishTraverse适配器来更改此设置。这有点邪恶,但这可能有用(在Plone 3中测试 - 我不是100%确定Plone 4中的默认行为):

from zope.component import adapts, queryMultiAdapter
from zope.publisher.interfaces.browser import IBrowserRequest 

from Acquisition import aq_base
from ZPublisher.BaseRequest import DefaultPublishTraverse
from Products.CMFCore.Skinnable import SKINDATA, SkinnableObjectManager

from thread import get_ident

_MARKER = object()

class SkinnableTraverser(DefaultPublishTraverse):
    adapts(SkinnableObjectManager, IBrowserRequest)

    def publishTraverse(self, request, name):
        """Let the default traverser do its job, but if the thing that was
        returned was from a skin layer and there's a view with
        the same name, let the view win.
        """

        gotten = super(SkinnableTraverser, self).publishTraverse(request, name) 

        if not name.startswith('_') and not name.startswith('aq_'):
            sd = SKINDATA.get(get_ident())
            if sd is not None:
                ob, skinname, ignore, resolve = sd
                if resolve.get(name, None) is aq_base(gotten):
                    # This was retrieved as a skin resource
                    # Check if it could've been a view also

                    view = queryMultiAdapter((self.context, request), name=name)
                    if view is not None:
                        return view.__of__(self.context)

        return gotten

您需要注册:

<adapter factory=".skins.SkinnableTraverser" />

可能在overrides.zcml中。另一种选择是在请求上使用更具体的标记接口,例如一个通过browserlayer.xml导入步骤安装。

马丁

答案 2 :(得分:2)

我不确定,但你可以快速做的是尝试使用plone_skins的“custom”文件夹。

您还可以尝试http://plone.org/documentation/kb/applying-a-custom-view-to-a-specific-folder

中的“替代”方式