我正在尝试在plone.app.theming iting-controlpanel中使用一个参数表达式,它从portal_registry获取一个值,以便在主题的rules.xml文件中使用。
目标是如果在注册表中设置了布尔值,主题可以允许/禁止某些内容。
所以我的参数表达式(在主题控制面板中)是
enable_ad_tags = python:context.portal_registry['lw.portal.enableadtags']
portal_registry中有一个相应的布尔字段。
rules.xml文件具有以下规则:
<!-- Global Ad Tags -->
<drop css:theme="#globalAdTags" if="not($enable_ad_tags)" />
问题是在我的本地计算机上我一直在控制台中收到此错误:
c2014-08-08 09:49:19 ERROR plone.transformchain Unexpected error whilst trying to apply transform chain
Traceback (most recent call last):
File "/Users/aaronwilliams/.buildout/eggs/plone.transformchain-1.0.3-py2.7.egg/plone/transformchain/transformer.py", line 48, in __call__
newResult = handler.transformIterable(result, encoding)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/transform.py", line 179, in transformIterable
params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/utils.py", line 630, in prepareThemeParameters
params[name] = quote_param(expression(expressionContext))
File "/Users/aaronwilliams/.buildout/eggs/Zope2-2.13.20-py2.7.egg/Products/PageTemplates/ZRPythonExpr.py", line 48, in __call__
return eval(self._code, vars, {})
File "PythonExpr", line 1, in <expression>
File "/Users/aaronwilliams/.buildout/eggs/AccessControl-3.0.6-py2.7-macosx-10.8-x86_64.egg/AccessControl/ImplPython.py", line 675, in guarded_getattr
v = getattr(inst, name)
AttributeError: 'DirectoryResource' object has no attribute 'portal_registry'
我试图在这里使用的模式有问题吗?
有没有更好/更安全的方法来实现这一目标?
答案 0 :(得分:1)
使用portal
代替context
无效:
enable_ad_tags = python:portal.portal_registry['lw.portal.enableadtags']
恕我直言context
也应该有用,或者上下文不像它那样,或者命名错误。