Forum Discussion

lorseau's avatar
13 years ago

Component and parameters

Hello,

 

Is it possible to send/give parameters to a custom component?

 

I also thought to have two components, one with the parameters (variables) and one with the code, but the variables are not recognize on the second one so it doesn't work ;o(

 

Thanks,

Laurent

  • The easiest would probably be to pass on that parameter on client side via JavaScript. But that's probably also the least secure way of doing so.
    As far as I know it's not possible to manipulate session data via freemarker in a component which would be the second way I could think of it to work.

    Maybe you can share some more details of what you roughly want to achieve, e.g. which type of parameters you want to pass on to a component. There might be different ways to get the same result.
  • AdamN's avatar
    AdamN
    Khoros Oracle

    When you say parameters, are you referring to URL parameters (ie. query string parameters). If so, you can use the http.request context object  to get the value of query string parameters. Here's a simple example

     

    <#assign val = http.request.parameters.name.get("myParameter", "default value") /> 
    myParameter: ${val}

    You can specify your own name for the parameter, as well as whatever default value you'd like to assign if the parameter isn't present in the query string.

     

    Alternately, if you want to parse out the request URL, you can use http.request.url to get the URL of the current page, and then freemarker has many built-ins for strings, such as split, substring, index_of, etc.

     

    Here's more on the built-ins:

    http://freemarker.sourceforge.net/docs/ref_builtins_string.html

     

    And here's more on the http.request context object:

    http://lithosphere.lithium.com/t5/Developer-Knowledge-Base/Context-objects-for-custom-components-http-request/ta-p/9323

     

    I hope this helps!

     

    -Adam

    • for the moment, on the top of my component i have these variables / parameters

       

      <#assign paramBoxTitle             = "What's new in the Community" />
      <#assign BoxType                   = "mgc-object-world" />
      <#assign paramNbItemMax            = 5 />
      <#assign paramPageSize             = 200 />
      <#assign paramBoardTypes           = ["all"] />
      <#assign paramCategories           = ["all"]>
      <#assign paramBoards               = ["Welcome", "Feedback"]>
      <#assign paramExcludeCategories    = [""]>
      <#assign paramExcludeBoards        = [""]>
      <#assign paramBoardId              = "" />

       

      I wanted to know if it's possible to get these values from another component or via the <component id="MEGAWhatsNewForum"/> which is on the page.

       

      Thanks,

      Laurent

       

      • AdamN's avatar
        AdamN
        Khoros Oracle

        Ah, I think I see now. So essentially you have a bunch of variables that you want to use in multiple places. Are these variables final, or do you intend to update the values?

         

        If the values will not be changed, you can use the freemarker "include" directive to insert the component containing your variables into other components.

         

        For example, if you had a component containing all these variables named "global-vars", you could add this to all the components that you wanted to use these variables:

        <#include "global-vars" />

        Keep in mind that this approach will only work if you don't plan to update the values of the variables in "global-vars". If you've included "global-vars" in components A and B, updating the value of one of the variables in A will have no impact on B. Each component essentially gets their own copy of the original code from "global-vars".

         

        If you want to be able to update a variable in component A and have it impact component B, that's going to be more tricky and I'd like to understand more about what you're trying to accomplish.