Had to do a very useful and ugly but also smart hack in Plone today.

In the portal root I have a Document with Id index_html that the client is changing with the WYSIWYG editor. What I wanted to do was to change some METAL calls in the <head> tag of that one document. In fact, what I wanted to do was to cover up the left hand column which is done this way:


  <head>
       <metal:override fill-slot="column_one_slot" />
 </head>

The problem was that the index_html Document is a Document so I can't edit it's TAL. I could have customized document_view.pt but that would have applied for all Document objects in the site. Here's how I solved it:

I renamed index_html to index_html_content and created a Page Template object in the portal root. The code for this one I got from portal_skins/plone_content/document_view.pt. Then I added the metal:override as shown above.

But I wanted this new index_html to render the content of the index_html_content object so that in, index_html I can (continue to) do stuff like here/getBody and here/Title. So what did I do? Here's a cut down copy of the index_html code:


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
     lang="en"
     metal:use-macro="here/main_template/macros/master"
     i18n:domain="plone">
 <head>
       <metal:override fill-slot="column_one_slot" />
 </head>
 <body>
 <metal:main fill-slot="main">
   <!-- here's my hack! --> 
   <tal:hack define="here nocall:here/index_html_content">
     <tal:main-macro metal:define-macro="main"
          tal:define="len_text python:len(here.text);">
       <h1 tal:content="here/title_or_id" class="documentFirstHeading">
         Title or id
       </h1>
       [... stuff hidden ...]
     </tal:main-macro>
   </tal:hack>
 </metal:main>
 </body>
 </html>

That didn't hurt, did it?

Comments

Peter Bengtsson

Update. A consequence is that the title can become "index_html" which isn't very nice.

Your email will never ever be published.

Previous:
Gmail shortcuts April 26, 2005 Linux
Next:
The Geeks Revenge April 29, 2005 Misc. links
Related by category:
Interesting lesson learnt on shortcut taking in usability August 2, 2007 Plone
Learning about ATFolder's security March 22, 2007 Plone
World Plone Day here in London, England October 21, 2008 Plone
Related by keyword:
Interview with Varg Vikernes July 1, 2008 Music
The meaning of "hacking" March 13, 2004 Misc. links
Kalle Kappner - Opeth and Pain of Salvation piano tribute August 19, 2008 Music
Tip: Printer friendly pages with Page Templates in Zope March 24, 2008 Zope