Customize Plone view class without touching the template

176 views Asked by At

If a view is registered like this, with the template definition in zcml:

<browser:page
    name="original-view"
    class=".original_view.View"
    permission="zope2.View"
    for="*"
    template="original_template.pt"
    />

and i want to customize only his class in my product, is there a way to do it without customizing also the template?

1

There are 1 answers

3
Mathias On BEST ANSWER

You have to wrap the browser:page by <configure package='XXXX'>

That means your then in scope of this packge.

Example:

<configure package="original.package.browser">
    <!-- custom view -->
    <browser:page
        name="original-view"
        class="your.package.browser.View" <!-- Full dotted name to you custom view class -->
        permission="zope2.View"
        for="*"
        layer="your.package.interfaces.IYourPackageLayer" <!-- You should provide a browserlayer, otherwise you got a configuration conflict -->
        template="original_template.pt" <!-- template from original.package.browser -->
    />

</configure>

EDIT:

As @sdupton mentioned, I updated the example code snipped with a layer If you can't use a layer (BrowserLayer) you can put the code, without layer attribute into a overrides.zcml

You can also specify a more precise Interface in the for attribute