TAL here hack in Plone

28 April 2005   1 comment   Plone

Mind That Age!

This blog post is 12 years old! Most likely, its content is outdated. Especially if it's technical.

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.
Thank you for posting a comment

Your email will never ever be published

Related posts

Gmail shortcuts 26 April 2005
The Geeks Revenge 29 April 2005
Related by Keyword:
Orphaned Land - Jewish Muslim Metal 08 December 2009
Kalle Kappner - Opeth and Pain of Salvation piano tribute 19 August 2008
Interview with Varg Vikernes 01 July 2008
Tip: Printer friendly pages with Page Templates in Zope 24 March 2008
More crappy album covers 06 August 2006
Related by Text:
Tip: Printer friendly pages with Page Templates in Zope 24 March 2008
Goodies from tornado-utils - part 2: tornado_static 22 September 2011
How to use premailer as a command line script 13 July 2012
premailer.py - Transform CSS into line style attributes with lxml.html 11 July 2009
Comparing Ruby and PHP 21 September 2006