Forum Discussion

Kev_B's avatar
Kev_B
Advisor
7 years ago

Building a component to react to Custom Content

Hello all,

 

Been a while since I've asked an odd question - I'm looking at building a component to access a specific Custom Content, and then decide whether to show the component and how it should be displayed. This is decided based on the FreeMarker placed in the Custom Content box (to allow changes without having to re-write the component itself).

 

I know how to pull the Custom Content box from Admin and display it, I'm just curious if there's a way to make the component check the code within the Custom Content box, and then decide whether or not to display it?

 

Here's more of a breakdown of my train of thought:

 

Component - checks if users.role matches to anything with the Custom Content field. If the user's role isn't listed in the Custom Content text then the component will not display.

Custom Content - dictates the HTML to be displayed based on the users.role, which is checked within the Custom Content text.

 

I hope this makes sense - any suggestions gratefully appreciated.

  • You can use the below code to get custom content data in the component


    <#assign nodeType = coreNode.nodeType />
    <#assign nodeID = coreNode.id />

    <#if nodeType=='board'>
    <#assign content =
    restadmin("/boards/id/"+nodeID+"/settings/name/customcontent.10_text").value
    />
    <#else>
    <#assign content =
    restadmin("/categories/id/"+nodeID+"/settings/name/customcontent.10_text").value
    />

    • Kev_B's avatar
      Kev_B
      Advisor

      Thanks VikasB

       

      I'd seen that article when figuring out how to access the custom content.

       

      Which method would you recommend for checking if there's a variable within that, say checking if customcontent.#_text contains users.role, for example?

      • VikasB's avatar
        VikasB
        Boss

        Kev_B

        If there is a different role for different node, then you need to use below code using corNode id

        <#assign content =
        restadmin("/boards/id/${coreNode.id}/settings/name/customcontent.#_text").value
        />

        If checking for just same role on all the nodes then you can just use this one

        <#assign content =
        restadmin("/settings/name/customcontent.#_text").value
        />