Using asset listing as dynamic metadata values


(Mitch Kerry) #1

Hey all

Wondering if there is a way to use an asset listing to provide values for a metadata field?

For example, I have a folder of FAQs that is frequently added to and I want to be able to choose items from that folder in metadata to apply to a page, essentially a dynamic metadata field.

Can it be done?

thanks
Mitch


(John gill) #2

You can’t do this with a Metadata Select Field.

A Related Asset Metadata Field with a restricted root set to your FAQ folder might be closer to what you want though. You’d be picking an asset, rather than a value, which might be better then just a value depending on your use case. If you really only want the value the asset represents (name or some other property) rather than the asset itself, then you’d just have to change the keyword wherever you use the metadata value from %asset_metadata_FAQpicker% to something like %asset_metadata_FAQpicker^as_asset:asset_name%.


(Mitch Kerry) #3

Thanks @JohnGill…bit of a compromise but what I might have to go with… Be nice to see a select list of all the asset names though.


(John gill) #4

I suspect the obstacle to something like this would be that it complicates the performance profile of anything that needs to render the dropdown (_admin, Asset Builder, etc). At the moment it’s a straightforward “Just load the Select Metadata Field asset and its attributes and you have everything you need”. If it could be dynamic, then potentially it could take (much) longer, require (many) more queries, and could fail in various ways that you don’t need to worry about if you’re just loading a single attribute.

Best compromise might be a process to assist with updating the options in the Select Field asset - the options are stored in a serialised attribute called select_options that can be set by one of the APIs (JS or SOAP). You could make a utility page that grabbed the listing, PHP serialised it and then called setAttribute to update it.

It might even be possible to fully automate it with a trigger :thinking: … but I wouldn’t.


(John gill) #5

It turns out you can’t do either of these things :frowning:

Unfortunately it seems that if you try to set the select_options attribute on a select field asset using JS API the response indicates that it succeeded, but it actually empties the attribute leaving your select field with no options.

The trigger method doesn’t work either. It turns out that while you can set an asset’s attribute based on the contents of a listing, you can’t set a serialize type attribute like select_options.

I suspect that that particular attribute is just “special” in some way, the _admin interface must do something other than just a regular setAttribute so the APIs don’t work. Looks like you’re stuck with the Related Asset Field workaround or manually updating the options.