How to simulate a simple forum

    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.

    <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 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)
    Tag page
    Viewing 8 of 8 comments: view all
    I'm using the same idea from the deki forums, but have modified my date to make it easier to read/more user friendly, and thought I'd share it. Using this script for new post:

    {{ web.link(page.path.."/"..date.month(date.now).."-"..date.day(date.now).."-"..date.year(date.now).." - Replace this text with post title","New Post") }}.

    Creates this:
    03-20-2008 - Replace this text with post title
    Posted 13:46, 20 Mar 2008
    It only took 6 months, but I finally found a way to get it to sort right without using a date in the title!
    Posted 20:58, 27 Aug 2008
    This is fantastic! Great job.
    Posted 09:55, 28 Aug 2008
    It is a great functionality, only I have some problems in running the script. I get the following message
    Function 'web.link' failed with response:missing value for parameter 'uri' (index 0) at the place where person who posted the subject...
    Really don't know what went wrong, I'm not that good with programming languages.
    Hope somebody can help me. edited 05:43, 23 Sep 2008
    Posted 05:31, 23 Sep 2008
    I get the same error message as mveenstra:
    Function 'web.link' failed with response: missing value for parameter 'uri' (index 0)
    Any help would be most appreciated.
    Posted 07:56, 6 Oct 2008
    >I get the same error message as mveenstra:
    >Function 'web.link' failed with response: missing value for parameter 'uri' (index 0)
    >Any help would be most appreciated.

    Me Too!!
    Posted 21:33, 26 Oct 2008
    I have the same problem and it's come out of the blue. The only thing I did was restrict access to the page to a group but I removed that when I discovered this problem. It didn't make any difference. HELP please!!

    Update:

    I had implemented as follows

    1. A top level page with a title Discussions
    This contained a message that access to discussions was for registered users
    I have a group called registered
    access to lower level pages was restricted to members of that group

    2. Below this a few pages each with a discussion forum
    Removing the restriction didn't solve the problem because the security remained defaulted to private.
    Changing the page back to a public page and all pages below it... worked.

    Great but... I would like to be able to have discussions not be public. This was quick and easy and would have been good if it had worked. However, what is really scary is seing a message go unanswered here for a month. I'm a student trying to use this for a project!
    edited 09:46, 29 Oct 2008
    Posted 09:24, 29 Oct 2008
    PJO if you want something answered it is best to post in the forums http://forums.developer.mindtouch.com/
    Posted 10:36, 26 Mar 2009
    Viewing 8 of 8 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by