Anonymous
Domino 2.0 Rich Internet Applications with IBM Lotus Notes/Domino
You are here: Today » Working with a master template
« LotusScript functions to generate valid XHTML forms
Looking for a nice file upload control »

Working with a master template

The idea is very simple: allow the definition of a HTML template with placeholders. These placeholders will be filled in by the application. The HTML template is stored in a document and QueryOpen agents fill the placeholders with content.

The HTML template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>[%pageTitle%]</title>
<link rel="stylesheet" type="text/css" href="[%dbPath%]css" />
<link rel="shortcut icon" href="[%dbPath%]gfi-favicon.ico" />
</head><body><div id="canvas">
<div id="identity">
<div id="user">[%userName%]</div>
<div id="title">[%dbTitle%]</div>
<img src="[%dbPath%]logo-gfi.gif" id="logo" alt="" />
</div>
<ul id="nav-top">[%navTop%]</ul>
<p id="trail">[%trail%]</p>
<div id="content">
[%pageContent%]
</div>
<div id="debug">[%debugOut%]</div>
</div></body></html>

The LotusScript

First, I made a replaceSubstring function:

Function replaceSubstring(Byval txt As String,Byval txt1 As String, Byval txt2 As String)As String
    replaceSubstring=Join(Split(txt, txt1), txt2)
End Function

And then the subroutine to fill in the placeholders. The values sometimes are simple values taken from config documents, sometimes the result of a function. When an error occurs, the subroutine only outputs the debug info:

Sub renderPage
    On Error Goto catch
    Dim html As String
    
    html=Join(MasterConfig.MasterTemplate, NEWLINE)
    html=replaceSubstring(html, "[%pageTitle%]", getTitle)    
    html=replaceSubstring(html, "[%dbPath%]", "/" & masterConfig.shortUrl(0) & "/")
    html=replaceSubstring(html, "[%userName%]", doc.userName(0))
    html=replaceSubstring(html, "[%dbTitle%]", getTitle)
    html=replaceSubstring(html, "[%navTop%]", getTopNav)
    html=replaceSubstring(html, "[%trail%]", getTrail)
    html=replaceSubstring(html, "[%pageContent%]", body.collapse(NEWLINE))
    
    debug.add "<p>Page rendered in " & Format((Getthreadinfo(6)-start)/Getthreadinfo(7), "0.00") & " sec.</p>"
    html=replaceSubstring(html, "[%debugOut%]", debug.collapse("<br />"))
    doc.ReplaceItemValue "PageHtml", html
    
    Goto finally
catch:
    debug.add "Error " & Err & " in line " & Erl & ": " & Error$
    doc.ReplaceItemValue "PageHtml", debug.collapse("<br />")    
    Resume finally
finally:
End Sub

Next steps

In a next post, I will show you some LotusScript functions I made to get Query_String values and to render valid XHTML forms.

Star rating

0%

Comments

  1. 19/09/2007 23:20:04, Jan Schulz

    I did something similar three days ago: http://www.openntf.org/Projects/codebin/codebin.nsf/CodeByDate/7EB8096EF5DDEBD386257358004B7122

    It's a little more generic: you can add tags and values for them (like field values, html'ised field values or @Formula) and the templatename can be computed on the form. I'm will add some import template function and will try to convert a internal DB to this in about a month...

  2. 20/09/2007 07:37:48, Tommy Valand

    That looks really nice. I've been thinking about trying out the exact same thing myself.

    The replaceSubstring-routine could look to be expensive for big pages (memory). If you don't have any inline "{", I'd think it would be a lot cheaper to pass the template to an evaluate-statement.

    E.g. 'doc is a stored document you get content from 'docHTML is DocumentContext of WQO 'html is the template-string

  3. 20/09/2007 07:49:29, Tommy Valand

    I'll try again. It seems you already have some replace in place :)<br> Please delete my previous comment. Hopefully this goes through as written. That looks really nice. I\'ve been thinking about trying out the exact same thing myself. The replaceSubstring-routine could look to be expensive for big pages (memory). If you don\'t have any inline \&quot;{\&quot;, I\'d think it would be a lot cheaper to pass the template to an evaluate-statement.

  4. 20/09/2007 07:56:22, Tommy Valand

    I give up. :)

    I've posted the response in my "workspace".

    http://blog.lotusnotes.be/workspace/pub/BHST-76CEAT

  5. 20/09/2007 09:07:13, Michel Van der Meiren

    @Jan: great! I will definitely have a look at your application.

  6. 20/09/2007 09:10:30, Michel Van der Meiren

    @Tommy: yes, I have a set of formulas that strip out the HTML from comments. It didn't work properly though. I will have a look. Thanks for your post in your workspace. If your code is more efficient, the only thing to solve is the { } characters inside the HTML fragments.

  7. 20/09/2007 09:46:16, Tommy Valand

    Not sure about this, but could you do something like this (creates four (?) more strings in memory):

    evalResult = Evaluate( |@ReplaceSubstring({| + Replace( Replace(html, "}", "$BL$"), "}", "$BR$" ) + |};| + from + |;| + to + |)|, doc )

    Call docHTML.ReplaceItemValue( "PageHtml", Replace( Replace(evalResult(0), "$BL$", "{"), "$BR$", "}" ) )

  8. 30.09.2007 18:35:34, Tommy Valand

    Just had my stab at templating in Domino, if you're interested.

    http://dontpanic82.blogspot.com/2007/09/php-like-templating-in-domino.html

To add a comment, log in or register as new user. It's free and safe.