Was this page helpful?

Simple Discussion Board

    Table of contents
    No headers

    The following code simulates a simple forum inside a wiki.  Use the "Add Comment" (at the bottom of the page) to reply.

    Note: an updated, template-based version may be found here.  Once we figure out a way to properly present templates on this wiki, we'll pull it back here.

    <p>{{wiki.create("Create New Topic",page.path,_,true,"Put Your Title Here")}}</p>
    <table cellspacing="0" cellpadding="4" border="1" block="var topics = [];
        foreach (var p in page.subpages) {
        var originator = wiki.getuser(web.list(p.api .. '/revisions?revision=1', '/page/user.author/username')[0]);
        var originator=(originator.id!=0)?originator:p.author;
        var lastAuthor = originator;
        var lastDate = date.format(p.date, 's');
        if (#p.comments != 0) {
        var lastComment = list.reverse(p.comments)[0];
        if (date.isafter(lastComment.date,p.date)){
        let lastAuthor = lastComment.author;
        let lastDate =date.format(lastComment.date, 's');
        }
        }
        let topics ..= [ { page:p, originator:originator, lastAuthor:lastAuthor, lastDate:lastDate } ];
        }
        let topics = list.sort(topics, 'lastDate', true);" class="table">
        <tbody>
            <tr>
                <th valign="top" style="width: 70%;">Topic/Starter</th>
                <th valign="top" style="width: 15%;">Last Post</th>
                <th valign="top" style="width: 7%;">#Views</th>
                <th valign="top" style="width: 7%;">#Replies</th>
            </tr>
            <tr foreach="var t in topics" class="{{__count % 2 == 0 ? 'bg1' : 'bg2'}}">
                <td valign="top"><font style="font-size: 17px;"><strong>{{web.link(t.page.uri, t.page.title)}}</strong></font> <br  />
                {{web.link(t.originator.uri, t.originator.name); }}</td>
                <td valign="top">{{date.format(t.lastDate,'yyyy-MM-d hh:mm');}} <br  />
                by {{web.link(t.lastAuthor.uri, t.lastAuthor.name)}}</td>
                <td valign="top">{{t.page.viewcount}}</td>
                <td valign="top">{{#t.page.comments}}</td>
            </tr>
        </tbody>
    </table>

    Object reference not set to an instance of an object (click for details)

        

    Was this page helpful?
    Tag page
    Viewing 6 of 6 comments: view all
    Special thanks to neilw for vast improvements on my original code.
    Posted 06:26, 30 Aug 2008
    The originator code was returning 0 on my wiki (perhaps because it is a private wiki). I put code in to trap this situation since it caused an error in the table output.
    Posted 06:50, 30 Aug 2008
    I neglected to mention the caveat that the originator code is vulnerable to security restrictions.

    I have an alternate solution, though, that I will possibly roll into this code when I get a chance. That is, insert the originator and original date into the topic itself using a template. Then, rather than do the API call, the originator can be found by a wiki.page() call. Another benefit is that this will fix the fact that the originator is currently not knowable on the topic page.

    I'll get to this soon! :-) edited 16:18, 31 Aug 2008
    Posted 16:17, 31 Aug 2008
    You should be able to get the originator by requesting the page metadata while providing ?revision=1.
    Posted 17:33, 31 Aug 2008
    That's what it's doing now, but I think it doesn't work if the page is restricted.
    Posted 02:49, 2 Sep 2008
    Hello World?
    Posted 07:35, 4 Feb 2010
    Viewing 6 of 6 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by