2012-04-27 02:37:06 Example of Logicless Templates
I didn't know the name of the system I've been using until late last year, seeming to be called logicless templates. Here's an example of how it works around here. Since logicless templates are utterly without code, they are language independent and one can use different frameworks on the same template files. In the following example, I'm using a python controller and for the html template file.

First the html template file:
( html )
  1  <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <title>Dummy title for fun</title>
6 </head>
7 <body>
8 <div id="linksTitle">Lynks of Olde:</div>
9 <ul id="links">
10 <li>
11 <span class="date"></span>
12 <a class="link"></a>
13 <span class="commentSpot">— <span class="comment"></span></span>
14 </li>
15 </ul>
16 </body>
17 </html>

And here's the python controller:
( python )
  1  from MinTS import *
2
3 page = Page( title='HyperJeff Blog Lynks of Olde' )
4 links = Table( 'links', 'blog' )
5
6 for link in links.each( sort='created', order='desc' ):
7 node = page.iterate( 'links' )
8
9 if not link['comment']:
10 node.remove( 'commentSpot' )
11
12 node.find( 'link' ).setAttribute( { 'href' : link['url'] } )
13
14 node.fill({
15 'date' : str( link['created'] ).split( ' ' )[0],
16 'link' : link['title'],
17 'comment' : link['comment'],
18 })
19
20 page.flush()

which produces the following output (using a real database in this example, but which had just some dummy data for demo purposes):
( html )
  1  <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <title>HyperJeff Blog Lynks of Olde</title>
6 </head>
7 <body>
8 <div id="linksTitle">Lynks of Olde:</div>
9 <ul id="links">
10 <li>
11 <span class="date">2012-04-26</span>
12 <a class="link" href="http://blog.hyperjeff.net/">First awesome link</a>
13 <span class="commentSpot">— <span class="comment">First link entry! Woo!</span></span>
14 </li>
15 <li>
16 <span class="date">2011-09-04</span>
17 <a class="link" href="http://scaldinghotwater.com/">Drug Cats</a>
18 <span class="commentSpot">— <span class="comment">Not what you think</span></span>
19 </li>
20 <li>
21 <span class="date">2010-12-03</span>
22 <a class="link" href="http://linksausages.com/">The Missing Link</a>
23 </li>
24 </ul>
25 </body>
26 </html>


Ultra-clean separation of duties. Even the template files can run thru HTML/XML/etc validators without having to first run it through the generation process. Dummy values in template files can be put in my designers, and even left in production code, since the controller will overwrite values left in.
Leave a comment