Forum Discussion

RyanMcClelland's avatar
6 years ago

Customize Post a Question Button

We would like to either suppress the Post a Question button or redirect it to the Case Portal page (/t5/crmsupport/page) if a user has a certain role.

Khoros previously developed a custom component for the post button. The code is pasted below. I'm wondering if more could be added to the text below to change the behavior of the button for two new roles.

 

<#include "theme-lib.common-functions.ftl" />

<#assign postUrl = "" />
<#switch page.name>
	<#case "CategoryPage">
		<#assign postUrl = webuisupport.urls.page.name.PostPage.path("category-id",coreNode.id).path("choose-node","true") />
		<#break>
	<#case "ForumPage">
	<#case "ForumTopicPage">
		<#assign postUrl = webuisupport.urls.page.name.PostPage.path("board-id",coreNode.id) />
		<#break />
	<#default>
		<#assign postUrl = webuisupport.urls.page.name.PostPage.path("choose-node","true") />
		<#break />
</#switch>

<#if postUrl?? && postUrl?has_content>
    <#attempt>
        <#assign rolesQuery = "select * from roles where users.id = '${user.id?c}'"/>
        <#assign rolesList = executeLiQLQuery(rolesQuery, false, true) />

        <#list rolesList as role>
            <#if role.name?lower_case == "direct">
                <#assign postUrl = postUrl.path("product-id","Direct")/>
            <#elseif role.name?lower_case == "office">
                <#assign postUrl = postUrl.path("product-id","Office")/>
            </#if>
        </#list>
  <#recover>
  </#attempt>
</#if>

<#assign postUrl = postUrl.build() />

<#if postUrl != "">
	<div class="post-btn-wrapper lia-button-wrapper">
		<a href="${postUrl}" class="post-btn lia-button lia-button-primary">${text.format("menubar.button.new_message")}</a>
	</div>
</#if>

 

  • Payal's avatar
    Payal
    6 years ago

    RyanMcClelland - You can wrap this line of code in attempt recover as shown below:

    <#attempt>

    <#assign postUrl = postUrl.build() />

    <#recover>

    </#attempt>

     

    Let me know if this helps.

     

    Thanks!

4 Replies

  • RyanMcClelland - I have made some updates in the code to get the Case Portal Page if a user has a certain role. 

    Code:

    <#elseif role.name?lower_case == "First_ROLE_NAME" || role.name?lower_case == "Second_ROLE_NAME">
    <#assign postUrl = "/t5/crmsupport/page" />

    Updated Code:

    <#include "theme-lib.common-functions.ftl" />
    
    <#assign postUrl = "" />
    <#switch page.name>
    <#case "CategoryPage">
    <#assign postUrl = webuisupport.urls.page.name.PostPage.path("category-id",coreNode.id).path("choose-node","true") />
    <#break>
    <#case "ForumPage">
    <#case "ForumTopicPage">
    <#assign postUrl = webuisupport.urls.page.name.PostPage.path("board-id",coreNode.id) />
    <#break />
    <#default>
    <#assign postUrl = webuisupport.urls.page.name.PostPage.path("choose-node","true") />
    <#break />
    </#switch>
    
    <#if postUrl?? && postUrl?has_content>
    <#attempt>
    <#assign rolesQuery = "select * from roles where users.id = '${user.id?c}'"/>
    <#assign rolesList = executeLiQLQuery(rolesQuery, false, true) />
    
    <#list rolesList as role>
    <#if role.name?lower_case == "direct">
    <#assign postUrl = postUrl.path("product-id","Direct")/>
    <#elseif role.name?lower_case == "office">
    <#assign postUrl = postUrl.path("product-id","Office")/>
    <#elseif role.name?lower_case == "First_ROLE_NAME" || role.name?lower_case == "Second_ROLE_NAME">
    <#assign postUrl = "/t5/crmsupport/page" />
    </#if>
    </#list>
    <#recover>
    </#attempt>
    </#if>
    
    <#assign postUrl = postUrl.build() />
    
    <#if postUrl != "">
    <div class="post-btn-wrapper lia-button-wrapper">
    <a href="${postUrl}" class="post-btn lia-button lia-button-primary">${text.format("menubar.button.new_message")}</a>
    </div>
    </#if>

     

    Please let me know if this works for you.

     

    Thanks!

  • Payal thank you so much for your reply! The code you provided did work in terms of redirecting the Post a Question button, but it also triggered an error message. I added the red box for emphasis, FYI.

    I inspected the element and the error message says div.lia-widget-not-found

    The Recent Activity drop-down is identified as 

    <span class="select2-selection__rendered" id="select2-messages-loader-type-container" role="textbox" aria-readonly="true" title="Recent Activity">Recent Activity</span>

    I'm not sure why this is affected, but here's what I pasted in:

     

    <#include "theme-lib.common-functions.ftl" />
    
    <#assign postUrl = "" />
    <#switch page.name>
    <#case "CategoryPage">
    <#assign postUrl = webuisupport.urls.page.name.PostPage.path("category-id",coreNode.id).path("choose-node","true") />
    <#break>
    <#case "ForumPage">
    <#case "ForumTopicPage">
    <#assign postUrl = webuisupport.urls.page.name.PostPage.path("board-id",coreNode.id) />
    <#break />
    <#default>
    <#assign postUrl = webuisupport.urls.page.name.PostPage.path("choose-node","true") />
    <#break />
    </#switch>
    
    <#if postUrl?? && postUrl?has_content>
    <#attempt>
    <#assign rolesQuery = "select * from roles where users.id = '${user.id?c}'"/>
    <#assign rolesList = executeLiQLQuery(rolesQuery, false, true) />
    
    <#list rolesList as role>
    <#if role.name?lower_case == "direct">
    <#assign postUrl = postUrl.path("product-id","Direct")/>
    <#elseif role.name?lower_case == "office">
    <#assign postUrl = postUrl.path("product-id","Office")/>
    <#elseif role.name?lower_case == "datafeed_member" || role.name?lower_case == "ec_member">
    <#assign postUrl = "/t5/crmsupport/page" />
    </#if>
    </#list>
    <#recover>
    </#attempt>
    </#if>
    
    <#assign postUrl = postUrl.build() />
    
    <#if postUrl != "">
    <div class="post-btn-wrapper lia-button-wrapper">
    <a href="${postUrl}" class="post-btn lia-button lia-button-primary">${text.format("menubar.button.new_message")}</a>
    </div>
    </#if>
  • Payal's avatar
    Payal
    Director
    6 years ago

    RyanMcClelland - You can wrap this line of code in attempt recover as shown below:

    <#attempt>

    <#assign postUrl = postUrl.build() />

    <#recover>

    </#attempt>

     

    Let me know if this helps.

     

    Thanks!