Using currentRefinedValues to produce a string output

Hello all,

I wanted to create a string that has the selected facets for a given attribute (lets say colour).

I saw currentRefinedValues and thought that this would be exactly what I needed.

However, the format I wanted is “Red, Green, Blue” as the string, but this widget creates a list of links and divs.

Is there a way to just get back a string of the selected facets, of a given attribute?

EDIT: Also I would like the string to come back “ALL” if nothing is selected.

Hi @daniel.avis, thanks for reaching out!

You went the right way, indeed currentRefinedValues serves this purpose but is meant to display the information to your users.

If you are just looking for a list of active facet refinements for an attribute, you can use getRefinements on the helper: this will give you a list of Strings (one for each value) that you can easily join afterwards.

As for having the string as “ALL” if nothing is selected, this would just mean a conditional check on the result of getRefinements to handle the case where the list is empty.

Let me know if this helps or if you have other questions :slight_smile:

1 Like

Perfect, this works just the way I wanted it.

However, is there one for the hierarchicalMenu? I tried the exact same way as the refinementList, but I get nothing back.

You’re welcome! Regarding hierarchicalMenu, I don’t know is.js very well but I see a few methods called getHierarch* in the Helper reference:

getHierarchicalFacetBreadcrumb ( facetName ) ⇒ array.<string>
// Get the current breadcrumb for a hierarchical facet, as an array

getHierarchicalFacetByName ( hierarchicalFacetName ) ⇒ object
// Helper function to get the hierarchicalFacet by it's name

getHierarchicalRefinement ( facetName ) ⇒ string[]
// Get the list of hierarchical refinements for a single facet

Give a try to those, one likely returns what you are looking for!

1 Like

And again you come up with the goods… Thank you!

1 Like