Re: Small patch for loop macro

"Hannes Wallnoefer" <[email protected]>
Newsgroups gmane.comp.java.helma.general
Message-ID <[email protected]>
Hi Maks,

thanks for the patch. The itemPrefix/Suffix parameters make sense, but
by composing a new string for each item instead of just using
res.write() you add a lot of overhead. I slightly modified your patch,
see attachment. Can you (or somebody else) please give it a try?

hannes

2007/5/10, Maksim Lin for technical support mailling lists
<[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
>
>
>

_______________________________________________
Helma-user mailing list
[email protected]
http://helma.org/mailman/listinfo/helma-user
loopmacro-hannes.diff (text/x-patch, 1.1 KB)
Index: core/HopObject.js
===================================================================
RCS file: /opt/cvs/apps/modules/core/HopObject.js,v
retrieving revision 1.4
diff -u -r1.4 HopObject.js
--- core/HopObject.js	23 Apr 2007 15:03:47 -0000	1.4
+++ core/HopObject.js	10 May 2007 09:56:00 -0000
@@ -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) {
@@ -135,9 +137,13 @@
         var itemlist = items.list(min, max);
     }
     var skinParam = {};
+    var itemPrefix = param.itemPrefix || "";
+    var itemSuffix = param.itemSuffix || "";
     for (var i=0; i<itemlist.length; i+=1) {
         skinParam.index = pagenr * pagesize + i + 1;
+        res.write(itemPrefix);
         itemlist[i].renderSkin(param.skin, skinParam);
+        res.write(itemSuffix);
     }
     return;
 };
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.