Small patch for loop macro

"Maksim Lin for technical support mailling lists" <[email protected]>
Newsgroups gmane.comp.java.helma.general
Message-ID <[email protected]>
Hi,

Ever since I discovered the loop macro (via the new reference docs) I've
found it *very* handy but one thing I missed was the ability to set a
prefix/suffix on each individual items skin render. So I've attached a
small patch to add this functionality to HopObject loop macro.

I find it very handy since sometimes I'm rendering items of a collection
as HTML list items, sometimes as options in a select element, sometimes
as just a comma seperated list and this way I can do it all with one
very simple skin.

Maks.

_______________________________________________
Helma-user mailing list
[email protected]
http://helma.org/mailman/listinfo/helma-user
HopObject-betterloop-patch.diff (application/octet-stream, 1.1 KB)
--- C:/helma/helma-1.6.0cvs/modules/core/HopObject.js-orig	Thu May 10 16:13:45 2007
+++ C:/helma/helma-1.6.0cvs/modules/core/HopObject.js	Thu May 10 16:24:50 2007
@@ -97,6 +97,8 @@
  *              (req.data.page determines the page number)
  *        sort: property name to use for sorting
  *        order: sort order (either "asc" or "desc")
+ *        itemPrefix: text to prepend to each items skin render
+ *        itemSuffix: text to append to each items skin render
  */
 HopObject.prototype.loop_macro = function(param) {
     if (!param.skin) {
@@ -134,12 +136,15 @@
     } else {
         var itemlist = items.list(min, max);
     }
+    var renderBuffer = "";
     var skinParam = {};
+    var itemPrefix = param.itemPrefix ? param.itemPrefix : "";
+    var itemSuffix = param.itemSuffix ? param.itemSuffix : "";
     for (var i=0; i<itemlist.length; i+=1) {
         skinParam.index = pagenr * pagesize + i + 1;
-        itemlist[i].renderSkin(param.skin, skinParam);
+        renderBuffer += itemPrefix+itemlist[i].renderSkinAsString(param.skin, skinParam)+itemSuffix;
     }
-    return;
+    return renderBuffer;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.