Yaws API discussion

Willem Broekema willem@REDACTED
Tue Jul 16 20:04:43 CEST 2002


Chris Pressey wrote:
> I agree that it is a Bad Thing<tm>, for the reason that interleaving
> different languages in the same source code file results a polyglot that
> is harder to understand and consequently harder to maintain.  In order to
> write a good 'active page' you need to write good HTML and good code, and
> few people specialize in both.

For an example of a web page template language that does not prevent you 
from editing the page with a (WYSIWYG) HTML editor (so logic and 
presentation can be done apart from each other): take a look at Zope Page 
Templates.

There, variables, loops, including other page snippets etc are all done by 
setting special attributes in the regular HTML tag. This allows the 
template page to be valid (X)HTML. There can be dummy contents that will 
replace at request time with the appropriate value.

Here's a simple example (the whole <span> tag will get replaced by the title):

   <span tal:replace="template/title">Title goes here...</span>

Iteration over a list (with one row dummy contents, so template can be 
previewed unparsed, to see how it will look after parsing):

  <tr tal:repeat="person cool_people">
     <td tal:content="person/name">Bill</td>
     <td tal:content="person/age">23</td>
   </tr>


It's probably a problem that Zope is Object Oriented: person/name means 
"the name attribute of the object named person". Erlang records are a poor 
substitute for this, especially because 'person/name' may also refer to the 
'name' *method* of the person object.

Nevertheless,  I like using attributes as template commands seems better 
than using special <? or [ tags, so that may be something to consider in Yaws.

Some ZPT links, if you're interested:

  ZPT Tutorial
   - http://www.zope.org/Wikis/DevSite/Projects/ZPT/TutorialPart1

  ZPT in the Zope Book
   - http://www.zope.org/Documentation/ZopeBook/ZPT.stx
   - http://www.zope.org/Documentation/ZopeBook/AdvZPT.stx (advanced)


- Willem




More information about the erlang-questions mailing list