TAL here hack in Plone

28 April 2005   1 comment   Plone

Powered by Fusion×

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:

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

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"
       <metal:override fill-slot="column_one_slot" />
 <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
       [... stuff hidden ...]

That didn't hurt, did it?


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

Related posts

Gmail shortcuts 26 April 2005
The Geeks Revenge 29 April 2005
Related by keywords:
Interview with Varg Vikernes 01 July 2008
The meaning of "hacking" 13 March 2004
Orphaned Land - Jewish Muslim Metal 08 December 2009
Kalle Kappner - Opeth and Pain of Salvation piano tribute 19 August 2008
Tip: Printer friendly pages with Page Templates in Zope 24 March 2008
More crappy album covers 06 August 2006
DOCTYPE in PageTemplates with METAL 09 February 2004
__call__ folderish Zope objects 19 December 2004