将视图添加到视图管理器中固定的特定位置
注意
由于此线程的成功结果,所提供链接中的文档已更新。它不再包含所描述的不完整信息。
我在获取 plone.portalheader viewletManager 中出现的视图并将它们添加到特定位置(不利用线性串联)时遇到问题。我的目标是使 html 代码看起来与我的 html 模板模型相同。我不希望也不要求视图改变位置,并且我希望看到其中几个元素最终出现在相同的总体标记中。
我一直在阅读以下文档,但它似乎与我的设置(即 Plone 4.1)冲突:
我不确定该特定页面是否已过时或不正确(看起来大多数对“tab”的引用都被空格替换。例如,现在是
)或者如果我正在做某事错了(我不会把它放在我身边)。
看起来当我想调用从示例创建的新标头时,在我的 Portal_header.pt 文件中引用 something.header
失败。如果有人可以查看这个示例并让我知道是否缺少任何重要部分,那对我来说将是一个巨大的帮助。
包括我的代码:
theme/browser/configure.zcml (部分):
<!-- The portal header -->
<browser:viewlet
name="plone.header"
manager="plone.app.layout.viewlets.interfaces.IPortalTop"
layer=".interfaces.IThemeSpecific"
class=".header.HeaderViewlet"
template="templates/portal_header.pt"
permission="zope2.View"
/>
theme/browser/templates/portal_header.pt:
<header>
<div class="container_12">
<div tal:replace="structure provider:theme.header" />
</div>
</header>
theme/browser/header.py:
from Acquisition import aq_inner
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.layout.viewlets import common as base
#import plonetheme.something.browser.viewlets.common as something #left over from original article
def render_viewlet(factory, context, request):
context = aq_inner(context)
viewlet = factory(context, request, None, None).__of__(context)
viewlet.update()
return viewlet.render()
class HeaderViewlet(base.ViewletBase):
index = ViewPageTemplateFile('header_items.pt')
def update(self):
base.ViewletBase.update(self)
self.subviewlets = {}
def renderViewlet(self, viewlet_class):
return render_viewlet(viewlet_class, self.context, self.request)
def render(self):
self.subviewlets["logo"] = self.renderViewlet(base.LogoViewlet)
self.subviewlets["search"] = self.renderViewlet(base.SearchBoxViewlet)
return self.index()
theme/browser/header_items.pt:
<header>
<div class="container_12">
<div tal:replace="structure view/subviewlets/logo" />
<div tal:replace="structure view/subviewlets/search" />
</div>
</header
这就是我根据我的文章修改的所有内容上面列出了。我不确定是否应该修改 viewlets.xml。
根据我对这篇文章的理解,它想通过利用 header.py 中提供的类来用 theme.header
覆盖并替换 Portal_header.pt 中的 plone.portalheader
。但是,我没有修改 viewlets.xml,我认为这是问题所在。或者它可能会喜欢这样的事实,即我将 plone.portalheader
替换为 theme.header
并且我没有将 configure.zcml 中的 viewlet 名称从 <代码>plone.header到theme.header
。
我已经尝试了一大堆我认为是解决方案的排列,但我无法让任何东西发挥作用,甚至尝试修改 viewlets.xml。
当我按照示例操作时,我收到一条错误消息:
ContentProviderLookupError(u'theme.header',)
NOTE
Due to the successful outcome of this thread, the documentation at the provided link has been updated. It no longer contains the incomplete information as described.
I'm having an issue taking viewlets that appear in the plone.portalheader viewletManager and adding them to specific locations (not utilizing the linear concatenation). My goal is to make the html code look identical to my html template mockup. I do not want nor require the viewlets to change positions and I would like to see a couple of those elements wind up in the same overarching markup.
I have been reading the following documentation, but it seems to be in conflict with my set up (which is Plone 4.1):
I'm not sure if that particular page is outdated or incorrect (it looks like most references to "tab" were replaced with spaces. eg, <table>
is now < le>
) or if I'm doing something wrong (which I wouldn't put it past me).
It looks like when I want to call the new header created from the example, citing something.header
fails inside my portal_header.pt file. If someone can eyeball the example and let me know if there are any important parts missing, that would be a huge help to me.
Including my code:
theme/browser/configure.zcml (portion):
<!-- The portal header -->
<browser:viewlet
name="plone.header"
manager="plone.app.layout.viewlets.interfaces.IPortalTop"
layer=".interfaces.IThemeSpecific"
class=".header.HeaderViewlet"
template="templates/portal_header.pt"
permission="zope2.View"
/>
theme/browser/templates/portal_header.pt:
<header>
<div class="container_12">
<div tal:replace="structure provider:theme.header" />
</div>
</header>
theme/browser/header.py:
from Acquisition import aq_inner
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.layout.viewlets import common as base
#import plonetheme.something.browser.viewlets.common as something #left over from original article
def render_viewlet(factory, context, request):
context = aq_inner(context)
viewlet = factory(context, request, None, None).__of__(context)
viewlet.update()
return viewlet.render()
class HeaderViewlet(base.ViewletBase):
index = ViewPageTemplateFile('header_items.pt')
def update(self):
base.ViewletBase.update(self)
self.subviewlets = {}
def renderViewlet(self, viewlet_class):
return render_viewlet(viewlet_class, self.context, self.request)
def render(self):
self.subviewlets["logo"] = self.renderViewlet(base.LogoViewlet)
self.subviewlets["search"] = self.renderViewlet(base.SearchBoxViewlet)
return self.index()
theme/browser/header_items.pt:
<header>
<div class="container_12">
<div tal:replace="structure view/subviewlets/logo" />
<div tal:replace="structure view/subviewlets/search" />
</div>
</header
That's all I have modified per the article I listed above. I'm unsure if I should modify viewlets.xml.
From what I understand of the article, it wants to override and replace the plone.portalheader
in portal_header.pt with theme.header
by utilizing the class provided in header.py. However, I'm not modifying viewlets.xml which is where I believe the problem lies. Or it could like with the fact that I'm replacing plone.portalheader
with theme.header
and I'm not changing the name of the viewlet in configure.zcml from plone.header
to theme.header
.
I've tried a whole bunch of permutations on what I believe to be the solution and I can't get anything to work, even trying to modify viewlets.xml.
When I follow the example I get an error message that says:
ContentProviderLookupError(u'theme.header',)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TAL 提供程序:表达式将仅呈现 portlet 管理器或 viewlet 管理器。它不适用于视图。这就是示例中存在
render_viewlet(factory, context, request)
快捷方式的原因。您想要的是
创建一个包含所有布局的视图(完成,HeaderViewlet)
将此视图放置在众所周知的位置viewlet 管理器(使用 /@@manage-viewlet 来确定哪个) - 这还没有完成
然后在这个新的视图中像你一样渲染子视图
如果你需要创建一个新的视图管理器(呃,痛苦和糟糕的工作)你可以按照此处的说明:
http://opensourcehacker.com/2011/11/29/creating-a-viewlet-manager-in-plone/
TAL provider: expression will only render portlet managers or viewlet managers. It does not work with viewlets. That's why there is
render_viewlet(factory, context, request)
shortcut in the example.What you want to is to
create a viewlet which contains all of your layout (done, HeaderViewlet)
place this viewlet in good known viewlet manager (use /@@manage-viewlet to figure out which) - this is not done
then in this new viewlet render subviewlets as you do
If you need to create a new viewlet manager (ugh, pain in the ass and shitty job) you can follow instructions here:
http://opensourcehacker.com/2011/11/29/creating-a-viewlet-manager-in-plone/