Peter Backx has created a UserTalk script that displays random pictures on the homepage of his Radio UserLand weblog.

The script's a nice, straightforward example of how to use UserTalk to read XML data from a file and do something with it.

I have modified his script to create a random text link that can be displayed on any Radio Web page. The link will be updated each time the page is republished, displaying a different link from an XML file called randomtextlinks.xml

Here's the script:

on randomTextLink() {
  «5/11/03; 11:08:43 AM by Rogers Cadenhead     «     «Based on the randomLink script by Peter Backx       «     «Modified to support text links instead of pictures   local (s = "", pc = file.getPathChar ());   local (f = + pc + "gems" + pc + "randomtextlinks.xml");   local (table);   xml.compile (file.readWholeFile (f), @table);   local (adrlinks=xml.getAddress(@table, "links"));   local (ltable=xml.getAddressList(adrlinks, "item"));   local (i = random(1,sizeof(ltable)));   local (name = xml.getAttributeValue(ltable[i],"name"));   local (url = xml.getAttributeValue(ltable[i],"pagename"));   s=""+name+"";   return s; }

To use the script:

  • Download the file workspace.randomTextLink.ftsc.
  • Open the Radio application (in Windows, right-click Radio in the System tray and choose Open Radio).
  • In Radio, choose the menu command File, Open, then find and open the file you just downloaded.
  • Radio asks if the file should be imported as workspace.randomTextLink. Click OK.
  • In your /www/gems folder, create an XML file called randomtextlinks.xml that contains a URL and text for one or more links (or use mine).

After the script has been installed and the XML file has been created, you can put the text <%workspace.randomTextLink()%> on any Web page or page template to call the macro, which displays a randomly selected link.

-- Rogers Cadenhead

Add a Comment

These HTML tags are permitted: p, b, i, a, and blockquote. A comment may not include more than three links. Participants in this discussion should note the site's moderation policy.