Forum Discussion

Hoekstra_VFZ's avatar
4 years ago

make a component appear only when the current environment is not-closed

Hi all,

On our Community we have closed sections where we test new products together with select users. We want to create a friendly warning when new testers are about to post outside of closed environments. This way we want to prevent leakage of sensitive information about not released products.

I need to build notifications for users with a specific role (product testers) when they are about to make a new topic - or placing a comment - outside of a closed forum. 

Here I have found Freemarker stuff to show a components for specific user roles: https://community.khoros.com/t5/Components-endpoints-and-the/Display-components-based-on-role/ta-p/42992

I did search for info on how to show components based on detection closed, hidden or open environments, but didnt find what I was looking for, so:

How can I make a component appear only when the current environment is not closed (and the user has a specific user role)?

With that figured it I can look to add it to the editor section on a topic, and add it to the new message page. Tips are welcome.

PS. I would really love to have parentnode and visibility (open, hidden, closed) added to the datalayer LITHIUM.CommunityJsonObject.Page - and userrole added to LITHIUM.CommunityJsonObject.User.

6 Replies

  • Hi!

    You could consider doing this via a custom quilt for the topic creation page / blog post page, with a custom component or custom content component that contains the warning message you want to display.  You’d need to manually set the quilt for the closed areas.

    Maybe not the most satisfying approach, and its feasibility depends on the number of closed areas you have... but it'll work.

    Hopefully someone has a more technical / API-based answer!

    Cheers!

  • Hoekstra_VFZ's avatar
    Hoekstra_VFZ
    Advisor
    4 years ago

    Jeff, thanks! Following the link you have shared I see suggestions how to make an IF statement using UserRoles and CoreNode ID's and CoreNode Ancestors.

    With this I should be able to make a component appear for Testmembers when the current node is not a test environment and they are about to write a comment.

    The real challenge will be to add a component to the postpage (start a discussion page). Can I even do that using the page and component editors in studio?

  • jeffshurtliff's avatar
    jeffshurtliff
    Boss
    4 years ago

    Yeah, depending on where you're wanting to place the component (e.g. banner across the top of the page, etc.) then you can just add the component to the PostPage quilt.

    In our environment I even had to get a bit more creative since the new support case form in the Case Portal also utilizes the PostPage and I wanted the editor to be two-thirds width in the Case Portal with a right rail for case information/policies (not unlike the Case Portal in Atlas) but wanted the editor to span the full width everywhere else.

    So I decided to create a custom layout for the PostPage which is shown below.

    In my layout I keep the main-content section for most discussion styles, and then created the support-main-content and support-side-content sections to be specific to the Case Portal.

    This is what the XML for my PostPage quilt looks like:

    <quilt layout="custom.postPage" nestable="false" disableTopCssClass="false">
      <add to="common-footer">
        <component id="quilt:Footer"/>
      </add>
      <add to="masthead-standard">
        <component id="custom.page.masthead"/>
        <component id="common.widget.breadcrumb"/>
      </add>
      <add to="support-main-content">
        <component id="custom.postPage.editor" casePage="true"/>
      </add>
      <add to="common-page-title">
        <component id="common.widget.page-title"/>
        <component id="custom.submit.integrations.ideas"/>
      </add>
      <add to="support-side-content">
        <component id="custom.case.casepageinfo"/>
      </add>
      <add to="main-content">
        <component id="custom.postPage.editor"/>
      </add>
      <add to="common-header">
        <component id="quilt:Header"/>
      </add>
      <remove from="sub-header-main" for="Header">
        <component id="common.widget.search-form"/>
      </remove>
      <remove from="header-right" for="Header">
        <component id="common.widget.search-form-toggle"/>
      </remove>
    </quilt>

    I wanted to be able to call the out-of-the-box editor component in both locations without actually rendering it twice and without having to create two separate custom components. (My Components tab in Studio is long enough already!), 

    So I wrapped the editor component in a custom component called custom.postPage.editor (shown below) and I included it twice in my quilt, while defining a component parameter called casePage in only one of them.

    <#-- Get the casePage component parameter value if defined -->
    <#assign casePage = env.context.component.getParameter("casePage")!"false" />
    
    <#-- Convert the parameter value to Boolean -->
    <#if casePage == "true">
      <#assign casePage = true />
    <#else>
      <#assign casePage = false />
    </#if>
    
    <#-- Define when the rich-text editor should be rendered -->
    <#if page.name == "PostPage">
      <#if casePage?? && casePage && page.interactionStyle == "support">
        <#-- Only render within the Case Portal -->
        <@component id="editor"/>
      <#elseif (!casePage?? || !casePage) && page.interactionStyle != "support">
        <#-- Only render when not within the Case Portal -->
        <@component id="editor"/>
      </#if>
    </#if>

     

    I know this is probably a weird use case but hopefully it helps illustrate how you can bend the PostPage to your will in Studio. 😊

  • TedV's avatar
    TedV
    Khoros Alumni (Retired)
    4 years ago

    Hi Hoekstra_VFZ

     

    If any of the comments answered your query, would you mind marking it as an accepted solution, please?

     

    Thanks!

  • Hoekstra_VFZ's avatar
    Hoekstra_VFZ
    Advisor
    3 years ago

    Thanks a lot for the detailed help jeffshurtliff! It has been months, I have totally missed this one. Nice to see you have built a custom layout for the postpage, I'll keep that in mind! Great tip.