TAL here hack in Plone
28 April 2005
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:
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/Title. So what did I do? Here's a cut down copy of the
<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?