Forum Discussion

mfeltscher's avatar
11 years ago

Display rating as stars in custom component

Hi there.

 

I'm currently working on a custom component where I have to display the lastest ratings along with some other information across the community.

 

I'm fetching the ratings using the API and I'm wondering if there is a way to display the rating value I get as a visual star rating using FreeMarker. As of right now I just do it by hand which is pretty hacky in my eyes.

 

 

Moreno

  • DougS's avatar
    DougS
    Khoros Oracle

    Hi Moreno,

     

    I'm not sure what you mean by doing it by hand -- can you post some code to demonstrate?  It seems like you should be able to take the average rating and caculate how many stars (out of 5) to give it based on the average.  I believe the way the core Lithium product does it out-of-the-box is by rendering different divs for each half-star and then putting different CSS classes on the divs based on whether or not the half star should show as "enabled" or "disabled".  You could do something similar, or render your 5-star rating image in a different way (there are many jquery plugins around that can render 5-star ratings).

     

    -Doug

    • mfeltscher's avatar
      mfeltscher
      Expert

      As of right now I only have a textual representation like this:

      <#-- TODO: Display as stars -->
      <#assign body = "Rating: ${review.reviews.rating.value} / 5" />

       

      No, there is no need to calculate the average rating.

       

      My question is: Is there some core Freemarker function / macro which takes a numeric rating value as a parameter and returns the HTML which is used to display the stars? I'm aware I could just do this by myself by copying / reimplementing the Lithium markup (different divs) but this doesn't seem very future-oriented to me. What if Lithium changes the markup in the future for example?

       

      Thanks,

      Moreno

      • DougS's avatar
        DougS
        Khoros Oracle

        Hi Moreno,

         

        There is unfortunately no ratings-related Freemarker objects right now.  At this point I believe you would need to re-build the UI for this yourself (which, like you say, could fall out-of-sync with any future changes Lithium makes).

         

        -Doug