Printing all option key text from a metadata select field


(Hugh McMaster) #1

Matrix Version: 5.4.3.1

Is there a way to print all option key text from a metadata select field in a standard page asset? (So, not just the selected option, but all keys in the dropdown menu.)

The metadata screen renders the select field as metadata_field_select_12345, but this doesn’t render on the frontend.

I found a post from mid-2014 that talks about using an Asset Builder, but I didn’t understand what I needed to do with it.

I’d like to use the metadata field as a source so I can reuse the entries in different parts of a website.

Thanks


(Bart Banda) #2

The way that people do that these days is to use the %asset_data% keyword to get all the select options in a JSON object, feed it to some SSJS and then print it that way. So for example:

<script runat="server">
var options = %globals_asset_data_attributes:1234^index:select_options^index:value%;
</script>

Where 1234 is the asset ID of the metadata select field.


(Hugh McMaster) #3

Wow. So simple!

Thanks, Bart. :slight_smile: