Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:55:44+00:00 2026-06-11T19:55:44+00:00

I have a grok’ed plone.directives.form code below: class EditForm(TreeFormMixin, form.SchemaForm): Edit form for our

  • 0

I have a grok’ed plone.directives.form code below:

class EditForm(TreeFormMixin, form.SchemaForm):
    """
    Edit form for our model.

    We got one dummy button which allows us to manually inspect the data postback values.
    """
    grok.context(ISiteRoot)
    grok.name("dgftreeselect-test")
    grok.require('zope2.View')

    ignoreContext = True
    schema = IFormSchema

    label = u"Tree selection demo and manual testing"

    @button.buttonAndHandler(u'Turbo boost')
    def handleApply(self, action):

        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        raise ActionExecutionError(Invalid(u"Please see that data stays intact over postback"))

it results to this form – which is not that good looking:

DGFs in the action

Since it is a demo form I’d like to keep all the related material in the same .py file. However, as the form is ugly looking, I’d like to inject a <style> CSS block on the page from a Python source code string to fix some of the most outstanding issues with the CSS styles.

What kind of hooks plone.app.forms / BrowserViews provide to inject your own <style> block in the <head> or in any part of the resulting HTML page? I prefer not to create any additional files and CSS registrations for this task.

Full source:

https://github.com/miohtama/collective.z3cform.dgftreeselect/blob/master/src/collective/z3cform/dgftreeselect/testform.py

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:55:45+00:00Added an answer on June 11, 2026 at 7:55 pm

    plone.app.z3cform and Zope browser views don’t provide any hooks to inject custom things into the head directly, but you can use a custom template by specifying the template attribute in the form class:

    template = grok.Template('path/to/template.pt')
    

    And then in template.pt, fill the style_slot to include your styles. The entire template could look like this:

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
          xmlns:tal="http://xml.zope.org/namespaces/tal"
          xmlns:metal="http://xml.zope.org/namespaces/metal"
          xmlns:i18n="http://xml.zope.org/namespaces/i18n"
          lang="en"
          metal:use-macro="context/main_template/macros/master"
          i18n:domain="plone">
    <body>
    
    <metal:block fill-slot="style_slot">
        <style type="text/css">
          /* insert styles here */
        </style>
    </metal:block>
    
    <metal:content-core fill-slot="main">
      <metal:content-core define-macro="content-core">
          <tal:button metal:use-macro="context/@@ploneform-macros/titlelessform" />
      </metal:content-core>
    </metal:content-core>
    
    </body>
    </html>
    

    This is not a best practice since the styles must be served every time the widget is rendered. Instead it’s usually better to register CSS in the portal_css tool.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dexterity content type based on plone.directives.form.Schema which has a number of
I'm getting confused with class inheritance for css. I have this: <ul id='grok'> <li
I have the following: public class Foo<T extends Grok> extends ArrayList<T> { } How
I have a Plone (4.2) form that is grokked. I want to have a
I have the following: <ul id='foo'> <li class='fooitem'> <ul class='grok'> <li class='grokitem'></li> </ul> </li>
I am trying to grok the output of a function which doesn't have the
I am trying to grok get a preliminary understanding of monads. I have a
have written this little class, which generates a UUID every time an object of
I have 2 scenarios. This fails: class F<X> { public X X { get;
I have finally started to take the time out to grok the continuous integration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.