Thursday, February 2, 2012

Community Server 6.0 Forum API Documentation Error on ForumThread Object - Excerpt is Depreciated

When coding with the velocity script extensions in Community Server 6.0, the API documentation is incorrect when accessing a ForumThread object.

Using Velocity Script, you can get a Thread object like this:
#set($thread = $core_v2_forumThread.Get($threadId))


According to the api documentation, you should be able to access the "Excerpt" of the thread, but this property is depreciated and always empty.
## Never populated and is depreciated
$thread.Excerpt

You can alternatively use the "Body" property of the $thread, but this property does not show up in the API Documentation.
## Returns the thread body, but not in the docs
$thread.Body


You can also display a smaller excerpt based on the body by stripping the HTML and truncating the text:
$core_v2_language.Truncate($core_v2_utility.Replace($thread.Body,"<(.|\n)*?>",""), 200, "...")

Just a quick screenshot of the API documentation for this object - note the "Body" property is not listed.

3 comments:

  1. Thanks for this blog - I've just subscribed. I've logged a ticket regarding the Excerpt property.

    For ForumThread.Body, this isn't actually a property, but a method. And the documentation should show it if you scroll down in the docs for the ForumThread. The method accepts a target format, and when not provided, assumes 'html'. Velocity is clever enough to infer .Body meant .Body().

    Also, for truncation, you shouldn't need to do your own HTML stripping, as Truncate already does that internally. This should work:

    $core_v2_language.Truncate($thread.Body(), 200, "...")

    Work is also logged to improve and expand this documentation.

    I'm looking forward to more posts!

    Michael Monteleone (Telligent)

    ReplyDelete
    Replies
    1. Michael, so the method $core_v2_language.Truncate($thread.Body(), 200, "...") will truncate AND strip HTML code?

      Delete