Customer Portal

Get Involved. Join the Conversation.

Topic

    Joao Fardilha
    Dynamic Base Message defined by phpAnswered
    Topic posted December 20, 2016 by Joao FardilhaBlue Ribbon: 750+ Points 
    649 Views, 8 Comments
    Title:
    Dynamic Base Message defined by php
    Content:

    Good afternoon guys,

    Sorry about it, but I am really out of depth at the moment, 
    I have these 4 base messages defined according to our products 
    CUSTOM_MSG_Product1SearchBarTitle
    CUSTOM_MSG_Product2SearchBarTitle
    CUSTOM_MSG_Product3SearchBarTitle
    CUSTOM_MSG_Product4SearchBarTitle

    On the site itself I am defining the message in PHP according to the p parameter I get from the URL, what happens is that when I throw in the html:
    <h1>rn:msg:#<?php echo $ProductSearch?>#</h1>
    ($ProductSearch being one of the above messages, which are correctly defined)
    the message is rendered before the php code runs, and therefore I get
    <h1><!--?=msgGetFrom(null, 1000191);?--></h1> 

    As anyone run into this before, or have any suggestions? I believe I can use a hook for this, but writing a class just to define which Base Message to use seems a bit of an overkill, but is this the only option?

    Code Snippet:

    Best Comment

    Barrilito van Dijk

    Hi,

    Try not to combine too much code. It will not be readable, and you would have to guess (and try) what will be loaded / rendered first. Go for a clear and save approach, use the conditional page tags to show / hide a message based on the product in the url. See the ci/admin area and look for the conditional tags under the page tags.

    Regards

    Comment

     

    • Narendra Muttineni

      Hi,

      To Fetch custom Message base from RightNow, you can use Connect PHP API.

      Step1: First fetch p parameter from URL

      2: Based on parameter, fetch message base by using below syntax. 

      $msg = RNCPHP\MessageBase::fetch( ID ); //message base ID

      or

      $msg = RNCPHP\MessageBase::fetch( "CUSTOM_MSG_TEST__PLAIN" ); //fetching by Name

      3. You can use the value in your view page <h1><?php echo $msg; ?> </h1>

      Hope it helps you.

      Thanks,

      Narendra

    • Joao Fardilha

      Thank you,
      Although I tried that I was not able to do so through RNCPHP, I will try to debug that at a later stage.

      The way I was able to do it though was much simpler, the #rn:msg:# widget uses the msgGetFrom() function to fetch the messages, this message takes two parameters, the second being the Key for the Custom Message, the first one, I was able to figure out that in my cases corresponds to 1.  
      Any idea where the documentation might refer this and similar RN functions to it?

    • Barrilito van Dijk

      Hi,

      Try not to combine too much code. It will not be readable, and you would have to guess (and try) what will be loaded / rendered first. Go for a clear and save approach, use the conditional page tags to show / hide a message based on the product in the url. See the ci/admin area and look for the conditional tags under the page tags.

      Regards

    • Joao Fardilha

      Thank you Barritlito this is indeed the approach I was looking for to begin with. I marked your answer as appropriate.

    • Barrilito van Dijk

      Hi João,

      Great to hear it works for you! Thank you for your quick response and closing of the thread by setting best answer, that helps others as well as they can now see the answer was given!

      Regards

    • Danette Beal

      I definitely share Barrilito's sentiment! 

      Thank you João for marking your best answer! The value this brings to the Community is insurmountable! 

      Regards,

      Danette, Community Manager

    • Rajan Davis

      1/16/2017 EDIT: Don't try to call Custom Message Bases in a widget controller. Instead you want to pass it in as a widget attribute, parse it in the widget controller, and then put the result into the widget's view.

      I had an issue where I needed to grab the keyword for a custom ResultInfo widget and inject it into a custom message base. This is so that I can use the same look and feel across various sites, but change the language as needed and retrieve the keyword that was used in the search.

       

      I created a custom message base (CUSTOM_MSG_NO_SEARCH_RESULTS_TAGLINE) using the following code block:

      <span>Sorry, we did not find any matches for </span>"<strong id="keyword">REPLACE_THIS TEXT</strong>"<span>.</span>
      <br class='hidden-sm'><br class='hidden-md hidden-lg'>
      <span>Check your spelling or use more general terms to try again.</span>
      

       

      In my Answers List page, I pass in the custom message base from above into my custom widget as follows:

      <rn:widget path="custom/reports/ResultInfo"
          label_no_results_suggestions="#rn:msg:CUSTOM_MSG_NO_SEARCH_RESULTS_TAGLINE#"
          label_no_results="#rn:msg:CUSTOM_MSG_NO_SEARCH_RESULTS_LABEL#"
          label_results_search_query="<br><br><h1 class='dynamic-header text-center'>#rn:msg:CUSTOM_MSG_SEARCH_RESULTS_LABEL#</h1><br>#rn:msg:CUSTOM_MSG_RESULTS_LABEL#"
          report_id="103666" 
      />
      

       

      and in the widget controller code, I added a function to retrieve the message base and inject the keyword and then call that function in the getData() function so that I can use that data in my view:

      function noResults(){
          $no_results = $this->data['attrs']['label_no_results_suggestions'];
          return str_replace("REPLACE_THIS_TEXT",getUrlParm("kw"),$no_results);
      

      }

      ...

      $this->data['noResultsLabel'] = $this->noResults();
      

      ...

       

      and in the widget view code:

      <?=$this->data['noResultsLabel']?>
      

       

      I am basically grabbing the custom message and replacing the text I need using PHP. I couldn't find this anywhere else on the forums, but this was the easiest way I could find to do this.

    • Erica (Leep) Anderson

      Thanks for taking the time to share your challenge and how you resolved it, Raj. We appreciate you building out the "collective community brain" with your experience and this code example! 

      Best,
      Erica, Oracle Service Cloud