[html-template-devel] Additions to html-template
Andrew Golding
andy at onshored.com
Mon Oct 2 18:56:07 UTC 2006
Hello to all the members of this list.
Recently at Onshore Development, we have started using HTML-TEMPLATE to
render web-pages in an application we call Woofie, which provides an
alternative interface to Webcheckout.
While working on html templates for Woofie, I found myself wanting some
extra abilities currently not available in HTML-TEMPLATE, mainly a
foreach style loop with the variable which holds the current value of
the list declared inside the tag, and the ability to use certain lisp
expressions (format inside tmpl-var's and equality comparisons, boolean
comparisons (or, and, etc.) inside of tmpl-if's).
I would like to see if other developers would find such features useful.
I currently have implemented both features I described to some degree in
the following fashion:
- the for-each style loop is represented in my templates as
TMPL_LOOP_FOR and closed with a /TMPL_LOOP. The tag looks for two
separate strings, one being the variable and the other being the list
(eg. <!-- TMPL_LOOP_FOR author authors -->). In the code, in each
iteration of the loop over authors, a (setf (getf values :author)
author) is performed (this should probably be changed into something
similar to the *value-access-function*, or the perhaps
*value-access-function* could be made setf'able?).
- TMPL_IF and TMPL_VAR can take a symbol or a list. The list is
deserialized from a string into a list of symbols or string literals
delimited by double quotes. A larger expression is built by making a
let, then evaluating the list. For example, the format expression in
<!-- TMPL_VAR (format nil "Displaying ~d results, displaying ~d through
~d." result-count first-result last-result) --> would get expanded to:
(let ((result-count (funcall *value-access-function* :result-count
values))
(first-result (funcall *value-access-function* :first-result values))
(last-result (funcall *value-access-function* :last-result values)))
(format nil "Displaying ~d results, displaying ~d through ~d."
result-count first-result last-result)), which passed to (eval) and
currently evaluated in the common lisp package (though evaluation should
probably get done in some user-specified package that can be made to
contain helper-functions for displaying data).
I would appreciate any comments, and I will try to answer any questions
should there be any (I'm guessing there will). The code can be found at
http://kfreedom.onshored.com/html-template-additions.lisp , and should
work with the standard html-template 0.7.0 package.
Regards,
Andrew Golding
andy at onshored.com
More information about the Html-template-devel
mailing list