Helma Logo
main list history

Helma 2 Templates - michi

NOTYETFINISHED

My current code snippet that tries to implement the ideas of the 'feburary-proposal':

  <h1><hc:this.msg id="site.topics.header">All topics</hc:this.msg></h1>
  <p><hc:this.topics.count>
    <ha:0><hc:this.msg id="site.topics.noTopics" /></ha:0>
    <ha:1><hc:this.msg id="site.topics.oneTopic" /></ha:1>
    <ha:n><hc:this.msg id="site.topics.moreTopics" /></ha:n>
  </hc:this.topics.count></p>
  <hc:site.loop alternate="2">
    <ha:prefix>
    <table>
      <tr>
        <th><hc:this.msg id="site.topics.tableHead.topic" /></th>
        <th><hc:this.msg id="site.topics.tableHead.numberOfStories" /></th>
      </tr>
    </ha:prefix>
    <ha:body>
      <tr class="row<hc:param.alternateCnt />">
        <td><hc:topic.name /></td>
        <td><hc:topic.count /></td>
      </tr>
    </ha:body>
    <ha:suffix>
    </table>
    </h:suffix>
  </hc:site.loop>
  # HopObject/macros.js
  function count_macro(param) {
    var cnt = this.count();
    if (param[cnt.toString()]) {
      res.write(param[cnt.toString()]);
    } else if (param["n"]) {
      res.write(param["n"]);
    } else {
      res.write(cnt);
    }
  }
  function loop_macro(param) {
    if (param["default"]) param["default"] = this.renderSkinAsString(createSkin(param["default"]));
    if (param["prefix"]) param["prefix"] = this.renderSkinAsString(createSkin(param["prefix"]));
    if (param["suffix"]) param["suffix"] = this.renderSkinAsString(createSkin(param["suffix"]));
    for (var i=0; i<this.count(); i++) {
      var obj = this.get(i);
      var skinParam = {};
      skinParam.cnt = i;
      if (param.alternate) skinParam.alternateCnt = i % param.alternate;
      if (param["body"]) {
        obj.renderSkin(createSkin(param["body"]), skinParam);
      } else {
        // render separate skin
        obj.renderSkin(param["skin"] || "listitem", skinParam);
      }
    }
  }
  function msg_macro(param) {
    this.renderSkin(createSkin(getText(param.id)));
  }
  # Global/functions.js
  function getText(id) {
    ..
    return str;
  }

Explanation: What has been before <% this.hello key1="value01" %>, is now <hc:this.hello key1="value01" />, which is nothing but a transformation of syntax. The only difference now is, that additional parameters to the macro can be specified by embedding ha-tags into the hc-tag. (hc stands for helma-call, and ha for helma-argument, whereas i'm open for better names)

Note: Lots of this.renderSkin(createSkin(.)) are needed in the above example, so an idea would be that Helma does that automatically for each 'ha'-macro argument, but then i wouldn't know how to push additional parameters to these strings/subskins.

Links to this page: Helma 2 Templates