Forum Discussion

iftomkins's avatar
11 years ago

Custom author component not working on Post Page

I created this author component that works on all pages I've seen, except for on the post page. This is the error: https://www.dropbox.com/s/fqirqygr4uhg7ag/Screenshot%202014-02-23%2013.11.04.png

 

Does anyone know how to modify this code so that it works on the post page just like it does in the message listing? Thanks!

 

<#--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">
        <table>
            <tr><td class="fonticon"><i class="fa fa-comment"></i></td><td class="count">${postCount}</td></tr>
        </table>
    </div>
</tr>
<div class="lia-message-author-kudos-count" title="Number of votes received by this author">
        <table>
            <tr><td class="fonticon"><i class="fa fa-thumbs-up"></i></td><td class="count">${kudosCount}</td></tr>
        </table>
</div>

  • Solved it--sort of. I test to see if the page is ReplyPage. If it is, I serve the default author component to avoid the error. If it's not, I serve the my custom author component.

     

    Again, big thanks to Claudius-- I noticed he used the default author component on the reply page, too.

     

    Here's the final code:

     

    <#--Custom author component with new order: Avatar, rank, posts, kudos. Original author component XML is     <component id="author"/>. On Reply page, defaults to Out-of-the-box author component. -->

    <#if page.name?lower_case == "replypage" >
        <@component id="author"/>
    <#else>

    <#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">
            <table>
                <tr><td class="fonticon"><i class="fa fa-comment"></i></td><td class="count">${postCount}</td></tr>
            </table>
        </div>
    </tr>
    <div class="lia-message-author-kudos-count" title="Number of votes received by this author">
            <table>
                <tr><td class="fonticon"><i class="fa fa-thumbs-up"></i></td><td class="count">${kudosCount}</td></tr>
            </table>
    </div>
    </#if>

  • I suspect the issue is with 'page.context.message.uniqueId'. You can debug it by testing page.context.message for null etc.

    • iftomkins's avatar
      iftomkins
      Maven

      Thanks, Nathan. I think you're probably right. 

       

      So if I test  page.context.message for null, and it is null, then how would I pull the author information? Is there another call that would work better from the compose page?

       

      I wonder how the native component does it...

      • iftomkins's avatar
        iftomkins
        Maven

        So, since these REST API calls don't work from the Post Page, it seems I need to get the data in another way. Are there different REST API calls that would return the same data, and would work from the post page?

         

        <#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}" />

         

        Thoughts appreciated!