[ZPT] TAL omitAllTags proposal cancelled

Godefroid Chapelle gotcha@swing.be
Fri, 22 Mar 2002 14:53:21 +0100


At 13:00 22/03/2002, Harry Wilkinson wrote:
>You may find it easier to read without so many 'tal:' scoping statements.
>Once you have put a tag in the TAL namespace with <tal:block> or similar, all
>its attributes will be in the TAL namespace by default.  So you can write:
>
><tal:tablename replace="table/name" />
>
>I don't think 'block' is a keyword here, I think you can use any word you
>like for the tag.  I could be wrong though.  Try it : )
>
>
>Harry


This is right : it does work with any identifier which is why my proposal 
should be cancelled.

IOW, 'tal:' prefixed elements are allowed and interpreted. Further, any 
''tal:' prefixed element has a default "tal:omit-tag" like behaviour.

Having said so, I think it is a real pity that nothing is mentioned in the 
TAL 1.4 specification document.
It's a long time I have been fighting with complex HTML rendering like the 
following.

<div tal:repeat="field python:form.get_fields()"
      tal:omit-tag="">
<div tal:define="fieldId python:field.getId()"
      tal:omit-tag="">
     <div metal:use-macro="here/PT_macros/macros/formatField"
          tal:omit-tag="">
         <p class="label">
             <span tal:content="python:field.get_value('title')"
                   tal:attributes="class
                   python:test(logic.database.isFieldPartOfPrimaryKey(fieldId),
                   'primaryKey', nothing)">
                 TEST
             </span>
         </p>
         <p class="widget">
             <span metal:fill-slot="renderFormulatorField"
                   tal:replace="structure python:field.render(value=None, 
REQUEST=request)">
        <input size="5" value="" name="field_XXX" type="text">
        </span>
         </p>
     </div>
     <div tal:omit-tag=""
          metal:use-macro="here/PT_macros/macros/formatErrorByField"
          tal:condition="python:errorMap.has_key(fieldId)">
         <p class="errorMessage"
            tal:content="python:errorMap[fieldId].error_text"></p>
     </div>
</div>
</div>

I quote the TAL 1.4 specification :

"If you want to override this ordering, you must do so by enclosing the 
element in another element, possibly div or span, and placing some of the 
statements on this new element."

But those nested 'div tal:omit-tag' are a real pain when debugging.


With 'tal:' prefixed tags, I can use the following :

<tal:formfields repeat="field python:form.get_fields()">
<tal:fieldid define="fieldId python:field.getId()">
     <tal:m_formatfield metal:use-macro="here/PT_macros/macros/formatField">
         <p class="label">
             <span tal:content="python:field.get_value('title')"
                   tal:attributes="class
                   python:test(logic.database.isFieldPartOfPrimaryKey(fieldId),
                   'primaryKey', nothing)">
                 TEST
             </span>
         </p>
         <p class="widget">
             <span metal:fill-slot="renderFormulatorField"
                   tal:replace="structure python:field.render(value=None, 
REQUEST=request)">
        <input size="5" value="" name="field_XXX" type="text">
        </span>
         </p>
     </tal:m_formatfield>
     <tal:m_formaterrorbyfield
     metal:use-macro="here/PT_macros/macros/formatErrorByField"
     condition="python:errorMap.has_key(fieldId)">
         <p class="errorMessage"
            tal:content="python:errorMap[fieldId].error_text"></p>
     </tal:m_formaterrorbyfield>
</tal:fieldid>
</tal:formfields>

which is still complex but much more readable.

And do not tell me that I am putting too much logic in my ZPT.
The logic stated is and only is presentation logic. The remaining logic is 
in Python scripts.

In conclusion, thanks for superb Page Templates tool. I hope that the info 
stated here will be included in the TAL spec.



--

Godefroid Chapelle

BubbleNet sprl
rue Victor Horta, 18 / 202
1348 Louvain-la-Neuve
Belgium

Tel + 32 (10) 459901
Mob + 32 (477) 363942

TVA 467 093 008
RC Niv 49849