themesplonediazo

Accessing portal_registry via plone.app.theming


I'm trying to use a parameter expression in the plone.app.theming theming-controlpanel that gets a value from the portal_registry to use within the rules.xml file of the theme.

The goal is that if a boolean is set in the registry, the theme can allow/disallow certain content.

So my parameter expression (in theming-controlpanel) is

enable_ad_tags = python:context.portal_registry['lw.portal.enableadtags']

There is a corresponding boolean field in the portal_registry.

The rules.xml file has this rule:

<!-- Global Ad Tags -->
<drop css:theme="#globalAdTags" if="not($enable_ad_tags)" />

The problem is that on my local machine i get this error in the console all the time:

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'

Is there a problem with the pattern I am trying to use here?

Is there a better/safer way to achieve this?


Solution

  • Using portal instead of context works:

    enable_ad_tags = python:portal.portal_registry['lw.portal.enableadtags']

    IMHO context should also work, or context does not behave like it does, or the naming is wrong.