Select options from related asset


#1

Matrix Version: 5.5

I am using the following keyword chain to display the select options from a metadata schema:

 %globals_asset_data_attributes:123456^index:select_options^index:value%

Which is printing fine.

However, I am now building this into a paint layout to enable users to select which schema to use. I am doing this by adding a related asset field (topic_related).

Testing. The following will print the correct asset ID for the selected schema on page.

%globals_asset_metadata_select_related%

However, when joining this to the above, I am not getting a result.

This is what I have chained together:

%globals_asset_data_attributes:globals_asset_metadata_select_related^index:select_options^index:value%

Suggestions as to how I can modify the above to get the desired result would be greatly appreciated.

Thank you.


(John gill) #2
%asset_metadata_select_related^as_asset:asset_data_attributes^index:select_options^index:value%

I always favour as_asset

%keyword_for_assetid^as_asset:keyword_for_desired_value%

over replace_keywords

%globals_keyword_for_desired_value:{keyword_for_assetid}%

It’s clearer and safer (fewer potential execution order issues).


#3

Thanks @JohnGill, this worked like a charm.
Merry Christmas :christmas_tree:


#4

Carrying on from this discussion, is there a way to set a default select if no value exists.

Such as:
%asset_metadata_select_related^as_asset:asset_data_attributes^index:select_options^index:value^empty:index:select_options^index:newvalue% ?

I can write a short bit of JS to accommodate the action, but still trying to get myself around chaining keywords and modifiers.

Thanks again


(John gill) #5

There’s no shortcuts, the fallback would need to be a whole keyword the same as the outer one. It’d probably be:

%asset_metadata_select_related^as_asset:asset_data_attributes^index:select_options^index:value^empty:{asset_metadata_select_related^as_asset:asset_data_attributes^index:select_options^index:newvalue}%