[ZPT] TAL omitAllTags proposal

Harry Wilkinson harryw@nipltd.com
Fri, 22 Mar 2002 12:00:15 +0000


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



On Friday 22 March 2002 11:08 am, Godefroid Chapelle wrote:
> We are using PageTemplates outside Zope to generate SQL data definitions.
>
> You find hereunder the type of code we wrote first in order to get
> well-formatted (human readable) SQL code.
>
> CREATE TABLE <tal:block tal:replace="table/name"/> (
> <tal:block tal:repeat="field table/field"> <tal:block
> tal:replace="field/name"/> <tal:block tal:replace="field/type"/><tal:block
> tal:condition="python:hasattr(field,'length')">(<tal:block
> tal:replace="field/length"/>)</tal:block><tal:block
> tal:condition="python:hasattr(field,'notnull')"> NOT
> NULL</tal:block><tal:block
> tal:condition="python:hasattr(field,'foreignkey')"> REFERENCES <tal:block
> tal:replace="field/foreignkey/table/name"/>(<tal:block
> tal:replace="field/foreignkey/field/name"/>)</tal:block>,</tal:block>
> PRIMARY KEY (<tal:block tal:repeat="primarykey
> table/primarykeys"><tal:block tal:replace="primarykey/name"/><tal:block
> tal:condition="not:repeat/primarykey/end">, </tal:block></tal:block>)
> );
>
>
> This type of code is quite difficult to debug because of the multiplicity
> of 'tal:block' elements.
> So we rewrote it like this :
>
> CREATE TABLE <tablename tal:omit-tag="" tal:replace="table/name"/> (
> <fields tal:omit-tag="" tal:repeat="field table/field"> <fieldname
> tal:omit-tag="" tal:replace="field/name"/> <fieldtype tal:omit-tag=""
> tal:replace="field/type"/><typelength tal:omit-tag=""
> tal:condition="python:hasattr(field,'length')">(<tal:block
> tal:replace="field/length"/>)</typelength><notnull tal:omit-tag=""
> tal:condition="python:hasattr(field,'notnull')"> NOT
> NULL</notnull><foreignkey tal:omit-tag=""
> tal:condition="python:hasattr(field,'foreignkey')"> REFERENCES <tablename
> tal:omit-tag="" tal:replace="field/foreignkey/table/name"/>(<fieldname
> tal:omit-tag=""
> tal:replace="field/foreignkey/field/name"/>)</foreignkey>,</fields>
> PRIMARY KEY (<primarykeys tal:omit-tag="" tal:repeat="primarykey
> table/primarykeys"><tal:block tal:replace="primarykey/name"/><comma
> tal:omit-tag="" tal:condition="not:repeat/primarykey/end">,
> </comma></primarykeys>)
> );
>
> where we get easier code to debug but with a lot of 'tal:omit-tag'.
>
>
> As I am generating SQL, I know I do not want any xml-like tags. I would
> like to state it and avoid repetitions of 'tal:omit-tag'.
> I would be able to use the following code:
>
> CREATE TABLE <tablename tal:replace="table/name"/> (
> <fields tal:repeat="field table/field"> <fieldname
> tal:replace="field/name"/> <fieldtype tal:replace="field/type"/><typelength
> tal:condition="python:hasattr(field,'length')">(<tal:block
> tal:replace="field/length"/>)</typelength><notnull
> tal:condition="python:hasattr(field,'notnull')"> NOT
> NULL</notnull><foreignkey
> tal:condition="python:hasattr(field,'foreignkey')"> REFERENCES <tablename
> tal:replace="field/foreignkey/table/name"/>(<fieldname
> tal:replace="field/foreignkey/field/name"/>)</foreignkey>,</fields>
> PRIMARY KEY (<primarykeys tal:repeat="primarykey
> table/primarykeys"><tal:block tal:replace="primarykey/name"/><comma
> tal:condition="not:repeat/primarykey/end">, </comma></primarykeys>)
> );