Forum Discussion

Claudius's avatar
13 years ago

Accessing Author information for custom component

I would like to add a custom component below the "Author" stock component that is shown to the left of each message. I've already found the page type to add my custom component (ForumMessage), but now I'm lacking a context object that grants me access to the author details (ID, SSO ID etc.).  Using ${page.context.message.author.id} I can only get the topic starter ID. I tried ${message.context}, but that does not exist - just in line with the context object documentation.

Anyone knows how to access a message author's information?

    • Perfect, thanks. Sometimes it's that easy that you can't find it.
      • iftomkins's avatar
        iftomkins
        Maven

        Thanks for the inspiration to change the author's component, Claudius. A big improvement over the default.

         

        I rebuilt our author component to use on the forum message page, and I wanted to share the code here. I think it uses a rest call instead of the env context object, but works all the same. It reorders it from the default, and adds kudos count. The <i> tags--such as <i class="fa fa-comment"></i>--are pulling icons from the Font Awesome icon set. The design is not final yet, but it looks something like this.

         

         

        <#--Custom author component with new order: Avatar, rank, posts, kudos. Original author component XML is     <component id="author"/> -->

        <#assign messageAuthorId = rest("/messages/id/${page.context.message.uniqueId}/author").user.id />
        <#assign messageAuthorLogin = rest("/messages/id/${page.context.message.uniqueId}/author").user.login />
        <#assign avatarUrl = rest("/users/id/${messageAuthorId}/profiles/avatar/url").value />
        <#assign kudosCount = rest("/users/id/${messageAuthorId}/kudos/received/count").value />
        <#assign postCount = rest("/users/id/${messageAuthorId}/posts/count").value />
        <#assign rankingName = rest("users/id/${messageAuthorId}/ranking/name").value />
        <#assign profileUrl = "/t5/user/viewprofilepage/user-id/${messageAuthorId}" />

        <div class="lia-message-author-avatar">    
            <div class="custom-avatar-wrapper">
                <div class="UserAvatar lia-user-avatar lia-component-common-widget-user-avatar">
                    <a class="UserAvatar lia-link-navigation" tabindex="-1" target="_self" id="link_39" href="${profileUrl}"><img class="lia-user-avatar-message" id="display" src="${avatarUrl}"></a>
                </div>
            </div>
        </div>
        <div class="lia-message-author-username">
            <span class="UserName lia-user-name">
                <a class="lia-link-navigation lia-page-link lia-user-name-link" href="${profileUrl}">
                    <span class="">${messageAuthorLogin}</span>
                </a>
            </span>    
        </div>
        <div class="lia-message-author-rank">${rankingName}</div>
        <div class="lia-message-author-post-count" title="Number of posts by this author"><i class="fa fa-comment"></i> ${postCount}</div>
        <div class="lia-message-author-kudos-count" title="Number of votes received by this author"><i class="fa fa-thumbs-up"></i> ${kudosCount}</div>