Forum Discussion

RobertT's avatar
6 years ago

page.context.user on MediaGalleryPage

Is there any particular reason why MediaGalleryPages don't have the page.context.user context variable available on them?

Found it a little strange, we're adding logic to our analytics and while the Profile pages and badges pages have the variable available for us to use, these pages don't.

Considering they belong to a user it would make sense for that context object to be available.

4 Replies

  • RobertT - Yes, it is indeed really surprising why this isn't available OOTB. As a workaround, you could pass it on to the next page in the URL and then use it in your analytics. Just override the media gallery component and add a custom link to pass the username to the next page.

    I hope this helps.

  • RobertT's avatar
    RobertT
    Boss
    6 years ago

    Unfortunately that's not a solution for us, we need the logic to run on that page as we're modifying analytics calls based and one of the conditions we're specifically picking up on is where a user is viewing their own profile/media gallery pages.

    Without the context object we can't compare the user ID to validate the user is looking at their own media gallery content.

  • Parshant's avatar
    Parshant
    Boss
    6 years ago

    RobertT 

    When you goto any media gallery page your URL will be "https😕/community.khoros.com/t5/media/gallerypage/user-id/34821".
    You can get the user-id for the media gallery by below code:

    <#assign urlList = http.request.url?split("/") />
    <#assign user_id = "" /> 
    <#list urlList as url_split>
        <#if url_split_index gt 0 && urlList[url_split_index - 1] == "user-id">        
            <#assign user_id = url_split />
        </#if>
    </#list>

     

    Above will give you the user-id of the gallery page you are viewing.
    you can check the condition with current login user(user.id) with below code after that.

    <#if user_id == user.id>
    [your condition code here]
    </#if>  

     

  • RobertT's avatar
    RobertT
    Boss
    6 years ago

    Parshant Thanks for this, unfortunately we need a solution that will work across all Media Gallery pages, this includes when a user browses their albums and views individual images in their gallery.