returning dynamic metadata fields from a multi-select using $_.query() tool
Hello,
We are using the awesome $_.query() tool and for the most part we are able to return most values (data, metadata, etc.). However, we are having troubles returning (looping) values for a multi-select. So far we can return a single value.
Here is the XML of a typical asset type we are looping through:
<system-index-block current-time="aaaa" name="current-page" type="folder">
<calling-page>
<system-page current="true" id="bbbb">
<name>cccc</name>
<title>ddddd</title>
<path>eeeee</path>
<site>ffff</site>
<link>gggg</link>
<dynamic-metadata>
<name>category</name>
<value>first value</value>
<value>second value</value>
</dynamic-metadata>
The following (partial) works:
#set ( $query = $_.query() )
#set ( $results = $query.byContentType("reference").sortBy("name").maxResults(-1).execute() )
#foreach ( $r in $results )
#set($meta = $r.metadata)
#set($name = $r.name)
#set($title = $r.metadata.title)
#set($section = $meta.getDynamicField('section').value)
However, when we use:
#set($category = $meta.getDynamicField('category').value)
it only returns of the 2 values from the above asset's XML structure.
We have tried:
##set($categories = $meta.getDynamicField('category')) ##nope
##set($categories = $_XPathTool.selectNodes($r, "dynamic-metadata[name='category']/value")) ## nope
##set($categories = $meta.getDynamicField('category').value) ##nope
##set($categories = $meta.getDynamicField('category').values) ##nope
##set($categories = $meta.getDynamicField('category').textValue) ##nope
##set($categories = $meta.getDynamicField('category').textValues) ##nope
##foreach($cate in $categories)
##set($category = $cate.value)
##end
How can we return (concatenate) the values for our multi-select dynamic metadata field?
Thanks in advance,
Jason H.
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 03 Mar, 2016 08:41 PM
Hi Jason,
When you have a moment, take a look at my response to this similar discussion for additional information on how to access the values from a multi-select field.
This particular discussion refers to structured data, but it should be the same scenario for dynamic metadata fields.
Please let me know if you have any questions.
Thanks!
2 Posted by jason.c.hoyt on 06 Mar, 2016 06:48 PM
Thanks for the direction. the following worked for us:
#set($category = [])
#set($categories = $meta.getDynamicField('category').values)
#foreach($cate in $categories)
#set($success = $category.add($cate)) ##using #set to silence the result
#end
${_DisplayTool.list($category," AND "," AND ","")}
- Jason H.
3 Posted by Ryan Griffith on 07 Mar, 2016 01:24 PM
Not a problem at all, Jason. I am glad to hear I was able to help point you in the right direction.
I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on 07 Mar, 2016 01:24 PM.