Helma Logo
main list history
previous version  overview  next version

Version 7 by michi on 06. December 2005, 21:18

<b>Syntax example for helma.skins.2.0: (by *matthias* - 2005/12/04)</b>
click on "attach" and download the file (if anybody can help me linking that file without destroying the layout here i would be thankful)

* is valid xml
* renders in a browser (without showing ugly server code) -> you might need to rename the extension to *.html
* seperates logic from template
* avoids the need of having many, many files...
* is based on the proposal from hannes (see link above)
* introduces &lt;h:Prototype.macroName /&gt; as an alternative to h:macro="Prototype.macroName"

the &lt;script runat="server"&gt; is just there to have the code in the same file. the idea would be to allow it just for file based skins and evaluate it just the same way as code in .js files.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:h="http://helma.org/schema/skins2.0">
<title>Helma 2.0 Templates</title>

<script type="text/javascript" runat="server"><!--

Macro.renderOpenTag = function(param, skins) {
if (param["h:nodeName"]) {
Html.openTag(param["h:nodeName"], param);

Macro.renderCloseTag = function(param, skins) {
if (param["h:nodeName"]) {

Site.prototype.topicList_macro = function(param, skins, macro) {
if (this.topics.count() == 0) return; // use default

// instead of this, we could introduce 'h:renderTag="true|false"' as a standard attribute
Macro.renderOpenTag(param, skins);

for (var i = 0; i < this.topics.count(); i++) {
var topic = this.topics.get(i);
res.handlers.topic = topic;
if (param["h:nodeName"]) {
Html.openTag(param["h:nodeName"], param);
Macro.renderCloseTag(param, skins);

TopicCommentMgr.prototype.count_macro = function(param, skins) {
var commentCnt = this.count();
if (commentCnt == 0) this.renderSkin(skins["no"]);
else if (commentCnt == 1) this.renderSkin(skins["one"]);
else this.renderSkin(skins["more"], {count: commentCnt});

alternative code structure:
# lowerCase indicates, that "topicList" is not a prototype -> code convention

# if the first part of a skin file name is CamelCase handle it as a prototype

// --></script>



<!--table h:macro="site.loop" h:collection="topics" h:as="topic" border="1"-->
<table h:macro="site.topicList" border="1" h:renderTag="true">
<tr h:name="prefix">
<th><h:msg name="site.topics.list.heading.topicName">Topic Name</h:msg></th>
<th><h:msg name="site.topics.list.heading.commentCount">Comment Count</h:msg></th>
<tr h:name="listItem">
<td><h:topic.name>Topic Name</h:topic.name></td>
<h:skin name="no"><!--h:msg name="comments.count.no">No comments yet</h:msg--></h:skin>
<h:skin name="one"><h:msg name="comments.count.no"><!-- 1 comment --></h:msg></h:skin>
<h:skin name="more"><h:msg name="comments.count.no"><h:param.count >34</h:param.count> comments</h:msg></h:skin>
<!--tr h:name="default">
<td colspan="2" align="center"><h:msg name="site.topics.list.isEmpty">This list is empty</h:msg></td>