Helma Logo
main list history

Helma 2 Templates - matthias

by matthias - 2005/12/04

it:

Note:
the <script runat="server"> 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"
			"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:h="http://helma.org/schema/skins2.0">
	<head>
	<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"]) {
			Html.closeTag(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;
			topic.renderSkin(skins["listItem"]);
			delete(res.handlers.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
  myExtension/code/topicList.macros.js    
	# if the first part of a skin file name is CamelCase handle it as a prototype
	myExtension/code/Site.topicList.example.skin
	myExtension/code/Topic.listItem.skin
	*/
	// --></script>
	</head>
	<body>
	<!--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>
		<tr h:name="listItem">
			<td><h:topic.name>Topic Name</h:topic.name></td>
			<td><h:topic.comments.count>
			<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>
		</h:topic.comments.count></td>
		</tr>
		<!--tr h:name="default">
			<td colspan="2" align="center"><h:msg name="site.topics.list.isEmpty">This list is empty</h:msg></td>
		</tr-->
	</table>
	</body>
	</html>

Links to this page: Helma 2 Templates