Print all options of a select metadata field on frontend


(Nic Hubbard) #1

I am needing to list all of the options that are contained within a Metadata Select field. Is there a keyword that can print all of these out?


(Cgrist) #2

I was looking into this recently...  I could see the attribute being set in the logs, I think it was "select_options", but the %asset_attribute_select_options% keyword didn't work. 

 

I ended up using the JS API to get the list, as getAttributes gets all attributes of an asset, including ones that don't have a keyword. I used getMetadataSchema to get the asset IDs of all fields, then one batch request to getAttributes with all of the fields, then you've got all details for the schema. This was ok in this project as it was a JS based website, but I don't know a way to get this information with keywords.


(Nic Hubbard) #3

I ended up using the JS API to get the list, as getAttributes gets all attributes of an asset, including ones that don't have a keyword. I used getMetadataSchema to get the asset IDs of all fields, then one batch request to getAttributes with all of the fields, then you've got all details for the schema. This was ok in this project as it was a JS based website, but I don't know a way to get this information with keywords.

 

Yeah, not going to work in this case...but thanks!


(Administrator) #4

Yea the other way I did it was to call a simple edit page with the simple edit keyword outputted for the select field. I either rested or ajaxed it in to my page i needed it on, can't remember which one, but that gave me just the select field which is what I needed anyways. But you could then just grab the select values or keys from that using js processing on the rest asset of client side. Big workaround, i know :(


(Nic Hubbard) #5

Yea the other way I did it was to call a simple edit page with the simple edit keyword outputted for the select field. I either rested or ajaxed it in to my page i needed it on, can't remember which one, but that gave me just the select field which is what I needed anyways. But you could then just grab the select values or keys from that using js processing on the rest asset of client side. Big workaround, i know :(

 

Yeah, I was thinking about doing this with an asset builder page and printing that keyword. 


(Bart Banda) #6

 

Yeah, I was thinking about doing this with an asset builder page and printing that keyword. 

 

Actually, I think an asset builder is what I used. You should then just be able to pull in the data with a %globals_asset_contents_raw% keyword 


(Nic Hubbard) #7

 

Actually, I think an asset builder is what I used. You should then just be able to pull in the data with a %globals_asset_contents_raw% keyword 

 

The thing I hate about this is all the form and javascript stuff that will get brought in with that...


(Bart Banda) #8

 

The thing I hate about this is all the form and javascript stuff that will get brought in with that...

You can try and do a regex replace on the keyword, that should work and just bring in the <select> field. 


(Clementoke) #9

Not sure if that's related to what I'm trying to do. I'm trying to format a metadata that outputs a semi-colon delimited list using Bootstrap's nav-pills class but I can't find a way of isolating each item to put it in an <li> tag.


(Bart Banda) #10

Not sure if that's related to what I'm trying to do. I'm trying to format a metadata that outputs a semi-colon delimited list using Bootstrap's nav-pills class but I can't find a way of isolating each item to put it in an <li> tag.

 

Are you just trying to output a semicolon separated metadata select field VALUE as an unordered list in <li> tags?


(Clementoke) #11

Yes and still be able to style the <li> tag.


(Nic Hubbard) #12

Yes and still be able to style the <li> tag.

 

Some here. 


(Bart Banda) #13

The way that I always do it is like this:

%asset_metadata_select^replace:;:</li><li>^tagif:li^tagif:ul%

Wraps the keyword in a <li> and <ul> tag only if it's not empty.

 

Is that what you were after?


(Clementoke) #14

Works a treat! definitely a keeper.

Thanks,

Clement