Jbot does not override my template

The view I want to override is defined by the "ActivateForm" class in a file named "covalent_member.py" inside the "behaviors" folder in the "ixds.covalent" package. So a place to put a custom template for my view inside this package (ixds.covalent) is

ixds/covalent/behaviors/covalent_member_templates/activateform.pt

      

(It works)

But then I try to make my settings in my theme package by creating a file called

ixds.covalent.behaviors.covalent_member_templates.activateform.pt

      

in my theme "override" the folder and nothing happens (of course, I tried restarting the instance, disabling and re-enabling the theme, reinstalling a few products, or even running buildout). Whether the custom template "activateform.pt" is still in my ixds.covalent package or not doesn't seem to make any difference (well, actually yes: if I remove it, I get the error "No such file or directory". However the problem is always the same: the template in the theme's "override" directory is never selected).

I have 5 other override templates in the same "overrides" folder and they all work. I am using z3c.jbot 0.7.1 (latest available), Plone 4.2.4 (latest stable) and the latest Git version of ixds.covalent from Github.

What could I be doing wrong?

+3


source to share


1 answer


I 'm assuming you are using this one ixds.covalent

on Github
.

There are two different mechanisms for registering templates here.

The class ActivateForm

derives from plone.directives.form.Form

, which in turn uses the package five.grok

. Therefore, it is ActivateForm

"grokked" at startup, which means that it is automatically registered with Zope without a separate entry in another file. Very handy for developers ixds.covalent

.

The grok engine also allows developers to create an auto-registered template for a form. They can create a directory named module plus '_templates' ( covalent_member_templates

) and a file corresponding to the class name ( activateform.pt

).

But in this case, the developers didn't decide to do it. plone.directives.form

exists to make it easier to create forms for developers, eg. without requiring a special template. As you've seen, there is nothing to stop you from creating this template in a package ixds.covalent

by following standard grok approaches.

But, of course, editing third-party packages in this way is not recommended. You can customize the form in your own package. But you cannot use z3c.jbot

because there is no existing template to override. You have to override the class ActivateForm

and use the grok template technique yourself.

So, in your my.theme package, make sure you have interfaces.py

:

from zope.interface import Interface

class IMyTheme(Interface):
    """Marker interface that defines a ZTK browser layer.
    """

      

In profiles/default/browserlayer.xml

:



<layers>
  <layer
      name="my.theme"
      interface="my.theme.interfaces.IMyTheme"
      />
</layers>

      

In configure.zcml

:

...
<!-- Grok the package -->
<grok:grok package="."/>
...

      

In covalent_member.py

:

from five import grok
from ixds.covalent.behaviors.covalent_member import ActivateForm \
    as OriginalActivateForm
from my.theme.interfaces import IMyTheme

class ActivateForm(OriginalActivateForm):
    grok.layer(IMyTheme)

      

In covalent_member_templates/activateform.pt

:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      i18n:domain="my.theme"
      metal:use-macro="context/main_template/macros/master">

    <metal:block fill-slot="main">

        <h1 class="documentFirstHeading" tal:content="view/label | nothing" />

        <p>Hey there. I'd really like you to fill out this form.</p>

        <div id="content-core">
            <metal:block use-macro="context/@@ploneform-macros/titlelessform" />
        </div>

    </metal:block>

</html>

      

... and you will see the customized template.

+3


source







All Articles