Bismi'llah ir-Rahman ir-Rahim
Code
    Free software.

daily link  Sunday, March 02, 2003

« Finally, download links »

Finally, with the help of Andy Fragen, I got the macro working to add download links to the sidebar.

3:00:52 PM  comment ()   permalink  comment on this post by email  


« Radio: macro frustration »

I just posted this to the Radio discussion list, but I'm also posting it here, in hopes that someone will be able to help me out.

I'm having a strange problem with macros. I created a new file (based on some code that Lawrence or someone posed on this list last year) in my Macros folder called myLinks.txt. The purpose of the macro is to insert the contents of a file called #links.txt into a rendered page, so that I can have custom links on a per-category basis. Here's what the file looks like (hope this doesn't get too munged when I post it):

on myLinks()
{
    local (categoryPath, path = user.radio.prefs.wwwfolder, s = " ");
    if defined(categoryName)
    {
        categoryPath = weblogData.categories.[categoryName].fileName;
        path = path + "\\categories\\" + categoryPath + "\\#links.txt";
        if file.exists(path)
        {
            s = "<!-- " + path + " -->\n" + string(file.readWholeFile(path));
        }
    }
    else
    {
        path = path + "\\#links.txt";
        if file.exists(path)
        {
            s = "<!-- " + path + " -->\n" + string(file.readWholeFile(path));
        }
    }
    return s;
};

Then, it my home page template, I added <%myLinks()%>. But what I got in the rendered page was

[Macro error: Can't call the script because the name "myLinks" hasn't been defined.]

As a test, I took a macro I that I'm already using succesfully (called subs() in the file subs.txt), copied it to a new file in the Macros folder called subs2.txt and edited the file to rename the routine to subs2(), then used the macro in a test page. But I got a similar error:

[Macro error: Can't call the script because the name "subs2" hasn't been defined.]

I must be doing something wrong, but what? The files are all valid UserTalk code, AFAIK. All the files in my Macros directory have the same permissions and attributes (I'm on Win2K).

Any ideas?


Update

Andy Fragen, no slouch when it comes to Radio scripting, suggests a workaround, which is to place the script into the workspace table and call it with <% workspace.myLinks() %>. This works fine — thanks, Andy!. But I'd still like to understand why it didn't work the other way.

11:44:40 AM  comment ()   permalink  comment on this post by email  


Copyright 2003 © Dave Seidel