<% Global.randomimage %>
macro renders a random image images can be either specified directly via the images-attribute, via their topic or via their site

  • Parameter images:
    String (optional), column separated list of image aliases
  • Parameter topic:
    String (optional), specifies from which topic the image should be taken all other parameters are passed through to the global image macro this macro is *not* allowed in stories FIXME: this function needs testing and proof of concept
Sourcecode in Global/macros.js:
1:   function randomimage_macro(param) {
2:      if (param.images) {
3:         var items = new Array();
4:         var aliases = param.images.split(",");
5:         for (var i=0; i<aliases.length; i++) {
6:            aliases[i] = aliases[i].trim();
7:            var img = getPoolObj(aliases[i], "images");
8:            if (img && img.obj) items[items.length] = img.obj;
9:         }
10:     } else {
11:        var top = param.topic;
12:        if (top && top.indexOf("/") >= 0) {
13:           var objPath = top.split("/");
14:           var s = (!objPath[0] || objPath[0] == "root") ? root : root.get(objPath[0]);
15:           top = objPath[1];
16:        }
17:        if (s==null) var s = res.handlers.site;
18:        var pool = (top) ? s.images.topics.get(top) : s.images;
19:        if (pool==null) return;
20:        var items = pool.list();
21:     }
22:     delete(param.topic);
23:     delete(param.images);
24:     var idx = Math.floor(Math.random()*items.length);
25:     var img = items[idx];
26:     param.name = img.alias;
27:     return image_macro(param);
28:  }