Forum Discussion

niten's avatar
niten
Guide
12 years ago

Include components into article

Hye everyone.

 

I'm wondering if there is a way in Lithium to include custom components into article like a tkb for exemple.

Maybe something like the shortcode API in WP which allow an admin to include a plugin into a post with shortcut code like [plugin name].

 

Something like that would be great.

 

If it doesn't exist, how can I choose to display a component or not according to the article.

For exemple, If I put a component on the tkb article layout. Can I choose to display this component only on choosen article ?

 

Thanks for reading.

 

 

4 Replies

  • DougS's avatar
    DougS
    Khoros Oracle
    12 years ago

    Lithium doesn't currently have a way to syndicate a component, or to place a reference to a component into a message or TKB article and have it render somehow.  Your only option is to place a custom component on one of the pages you can modify through the Page tab in Lithium Studio.

     

    You have a couple of options as to where you can place a custom component for a TKB article:

     

    1. You could add your custom component to the TKBArticlePage (in studio) -- you can place it above or below the article this way.
    2. You could add your custom component to the TKBMessage page (in studio) -- you can place the custom component closer to the actual article content this way -- a couple things to note about placing your component here:
      • Your component can get the currently rendering TKB article using the following freemarker expression:
        <#assign message_id = env.context.message.uniqueId />
        <#assign message = rest("/messages/id/" + message_id).message />
      • I believe it may cause your component to render inside of article comments as well, so you may need to add a conditional to check that this is the root message (because the tkb article is the "root" message and the comments are its "replies").  Something like this should do the trick:
        <#assign message_id = env.context.message.uniqueId />
        <#assign message = rest("/messages/id/" + message_id).message />
        <#if message.root.@href == message.@href>
          <#-- add component content here -->
        </#if>

    The examples above show you how to get a reference to the TKB article (using a server-side REST-like call, which returns a freemarker xml that matches the actual REST API resposne).  You can use that object to make additional checks taylored to your business needs to determine whether or not to display the content of the component.

     

    I hope that helps!

     

    -Doug

  • niten's avatar
    niten
    Guide
    12 years ago

    First of all, thanks for your answer Dougs.

     

    So if I understand well, my only option is to :

     - have a list with each tkb's href (or id) i want to display my component

     - In my component check if the tkb href attribut (or id) is within the list describe above

     - and then display (or not) the content.

     

    It thought about a solution like this, but it's not an optimal option since it would mean that every time someone of the communication add a tkb, he will need to ask me to add it in the 'display my component' list...

     

    Wich lead to my second question : is there a way, when someone create a new tkb, to add attributs in the tkb xml description wich is return by the rest API?

    So I could  get something like that :

     

     

    <#assign message_id = env.context.message.uniqueId /> 
    <#assign message = rest("/messages/id/" + message_id).message />
    <#if message.root.@href == message.@href AND message.root.@display_content==true>
    <#-- add component content here -->
    </#if>

     

    Again, thanks for reading.

     

    -niten

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    Hi Niten,

     

    The Lithium Platform supports the concept of what's known as Message Metadata, which allows you to associate custom key/value pairs with a message. You may have even seen some of these REST API calls while browsing through the Javadocs. Unfortunately, the ability to add new Message Metadata is not currently available through Studio, so you'll need to work with our Professional Services team in order to get the initial setup completed and make the form changes to add the field to the TKB message editor.

     

    If this is something you're interested in pursuing further, I'd suggest filing a case so that our Support team can put you in touch with a member of our Professional Services team.

  • niten's avatar
    niten
    Guide
    12 years ago

    Hye Adam,

     

    Thank you for your answer. This would be a perfecr solution for our needs.

    I think we have a meeting with someone from Lithium this week, so I will ask him then...

     

    Again, thanks for your answers Adam and Doug