Forum Discussion

iftomkins's avatar
11 years ago

Test interaction style of current node

How do I test, via freemarker, what the interactions style of the page I'm on is?

 

I need to run some code when I'm at this URL:

 

https://community.stage.fitbit.com/t5/Help-Forums/ct-p/product/interaction-style/idea

 

 

But I don't want the code to run when I'm at this URL:

 

https://community.stage.fitbit.com/t5/community/mobilecommunitypage/interaction-style/forum

 

 

I have the current node id: <#assign currentNodeId = coreNode.id />

 

Can I make a rest call and get the interaction style and use it in a conditional? I'd love something like:

 

If node.interactionStyle == idea {

//do this stuff

}

  • Thanks, Adam! I tried the get parameter method but I think that will only return ?parameters=likeThese. Parsing the URL itself worked, here's the solution:

     

        <#assign currentUrl = http.request.url />
        <#if currentUrl?contains("idea")>
            <#--We know it's an ideas board-->
        </#if>

     

    This also helped solve the issue where the current node.Id returns "discussions" when you're looking at a list of ideas boards and when you're looking at a list of forums boards (i thought IDs were unique?). Now we can filter by whether the URL contains "interaction-style/idea":

     

        <#assign currentUrl = http.request.url />
        <#if coreNode.id=="feedback">
            ${http.response.setRedirectUrl("t5/Help-Forums/ct-p/product/interaction-style/idea")}
        <#elseif coreNode.id== "discussions" && currentUrl?contains("interaction-style/idea")>
            ${http.response.setRedirectUrl("t5/Help-Forums/ct-p/product/interaction-style/idea")}
        </#if> 

     

    For anyone coming across this post, just a reminder that all this code needs to be run in the Page Initialization tab. To get access to the Page Initialization tab you must contact Lithium Support.

9 Replies

  • iftomkins's avatar
    iftomkins
    Maven
    11 years ago

    Thanks, but it did not work. I think page.interactionStyle only works on certain types of nodes, and category pages it does not work on.

     

    I'm currently accomplishing it with Javascript looking at the URL, but it's slower and messier:


                    var url = window.location.href;
                       if(url.indexOf("interaction-style/idea") > -1) {
                               // do some thing
                       } else {
                              //do something else
                       }

  • iftomkins's avatar
    iftomkins
    Maven
    11 years ago

    I'd like to perform a redirect on certain pages using Freemarker. To do this, I'd like to be able test for being on this page:

     

          https://community.stage.fitbit.com/t5/community/mobilecommunitypage/interaction-style/forum

     

    versus being on this page:

     

         https://community.stage.fitbit.com/t5/community/mobilecommunitypage/interaction-style/idea

     

    There must be a way to test the interaction style without using Javascript to look at the URL. I hope someone knows the answer!

     

  • AdamN's avatar
    AdamN
    Khoros Oracle
    11 years ago

    Hi iftomkins,

     

    Based on your latest example, it looks the page you're referring to is the MobileCommunityPage, which itself does not have an interaction style. Interaction style is a property that applies to discussion nodes such as forum, blog, idea, tkb, etc.. Rather on the MobileCommunityPage, you're able to filter content on that page by selecting an interaction style filter. So it sounds like what you're really interested in, is determining the value of a path parameter in the URL; namely whether the interaction-style path parameter in the URL is set to "forum" or "idea".

     

    I'd suggest checking out the http.request freemarker context object: http://lithosphere.lithium.com/t5/developers-knowledge-base/http-request-FreeMarker-context-object/ta-p/9323. There are a couple of methods there that should help you get this information without having to resort to using JavaScript. You may be able to use the http.request.parameters.name.get() method to get it directly. As a last resort, you could parse it from http.request.url.

  • iftomkins's avatar
    iftomkins
    Maven
    11 years ago

    Great! I'll work on that right now, thanks.

     

    In a similar vein, I'm trying to output the topic count for 3 top level categories via this rest call:

     

        http://community.lithium.com/community-name/restapi/vc/categories/id/[id]/topics/count

     

    One of the top level categories is 'Ideas". I can query the first two categories based on their id, but the ideas one is just an interaction style, with the Url:

     

    /t5/community/mobilecommunitypage/interaction-style/idea

     

    How would we query the number of topics within all ideas boards?

  • iftomkins's avatar
    iftomkins
    Maven
    11 years ago

    Thanks, Adam! I tried the get parameter method but I think that will only return ?parameters=likeThese. Parsing the URL itself worked, here's the solution:

     

        <#assign currentUrl = http.request.url />
        <#if currentUrl?contains("idea")>
            <#--We know it's an ideas board-->
        </#if>

     

    This also helped solve the issue where the current node.Id returns "discussions" when you're looking at a list of ideas boards and when you're looking at a list of forums boards (i thought IDs were unique?). Now we can filter by whether the URL contains "interaction-style/idea":

     

        <#assign currentUrl = http.request.url />
        <#if coreNode.id=="feedback">
            ${http.response.setRedirectUrl("t5/Help-Forums/ct-p/product/interaction-style/idea")}
        <#elseif coreNode.id== "discussions" && currentUrl?contains("interaction-style/idea")>
            ${http.response.setRedirectUrl("t5/Help-Forums/ct-p/product/interaction-style/idea")}
        </#if> 

     

    For anyone coming across this post, just a reminder that all this code needs to be run in the Page Initialization tab. To get access to the Page Initialization tab you must contact Lithium Support.

  • AdamN's avatar
    AdamN
    Khoros Oracle
    11 years ago

    Hi iftomkins,

     

    You're right, that method is for query string parameters. I got my methods mixed up. This is the one that can be used for path parameters:

    http://lithosphere.lithium.com/t5/developers-knowledge-base/webuisupport-FreeMarker-context-object/ta-p/9343

     

    One caveat though... because it returns a wrapped object, it may not be compatible with all path parameters. I've used it with the tag and page parameters before, but have had mixed results with others. If you've already got your code working, I probably wouldn't worry about it. Just an FYI for anyone else with similar issues.