Output metadata field as checkboxes on a front end


(Edinkin) #1

I have a metadata field setup as checkboxes on the backend multiples allowed, it is used to categorise assets.
I want to output the name of these checkboxes on the front end of the site.

I use asset listing to list assets to which these metadata applied and I want to output metadata options to use them as filters.

using metadata keywords I can output the value of the metadata field applied to the asset, but I need to output all of them.

I hope I made myself clear. I thought this would be simple, but the answer eludes me.

Similar to this https://www.aci.health.nsw.gov.au/resources/chronic-care/consumer-enablement/guide/resources where checkboxes are values of metadata.


(Harinder Singh) #2

Option1: You can hard code the filters manually. You will have more control on them.

Option2.

  1. Have a new Filter Schema with Filter Checkboxes and apply it to a Standard Page.

  2. In your asset listing, you can use the following keyword to pull the metadata values from the standard page with paint layout applied
    %globals_asset_contents_paint_layout_id_<paint_layout_id>:<assetid>%

  3. Use SSJS in the paint layout to format your filters accordingly.

It is bit of work in the beginning but easy to manage the filter list from metadata screen.


(Edinkin) #3

Thanks for reply.

Sorry I am not following on option 2.
I already have metadata schema applied to assets under the asset listing and a particular field in the metadata has multiple values say:

field=category
cat1 = 1
cat2 = 2
cat3 = 3
cat4 = 4

I want to be able to printout all options 1 through 4 not only the ones that selected for particular asset.

I am not very confident with JS, for now just wanted to be able to print out all the values.


(John gill) #4

The information you’re after is only available in the attributes of the Metadata Select Field asset itself. If you’re >5.4.2.2 you can get at this with a combination of SSJS and %asset_data_attributes%.

The attribute is called select_options, so essentially you want to grab that with SSJS, loop over it and spit out a checkbox for each item.

Assuming the field asset is #795, and it’s set up such that the exported CSV of the options looks like

a,Apple
b,Banana
c,Cherry
d,Date
e,Eggplant
f,Fig
g,Grape

then the code you want is[1]

<ul>
<script runat="server">
var options = %globals_asset_data_attributes:795^index:select_options^index:value%;
Object.keys(options).forEach(function(e,i) {
  print('<li><label><input type="checkbox" value="' + e + '"/> ' + options[e] + '</label></li>');
});
</script>
</ul>

Will produce.

image

[1] you should probably so some extra escaping of values in there


(Harinder Singh) #5

“I already have metadata schema applied to assets under the asset listing and a particular field in the metadata has multiple values say:_”

You are using asset listing to list assets with metadata field has multiple values selected. Setting up filters is totally seperate implementation which you can include either at the landing/listing page or at “Page contents” bodycopy of asset listing.

Try to think and implement it separately from your asset listing.

John’s solution is also good.


(Edinkin) #6

Thank you both much appreciated. I will give it a go.


(Chris Horikx) #7

Excellent, thanks John

I did a reduce instead of a forEach :slight_smile: