With the XPath Tool

If you're using an index block and the XPath Tool, you can target the name of your Custom Metadata Field in your XPath Syntax. Example:

#set ($department = $_XPathTool.selectSingleNode($page, "//dynamic-metadata[name='department']/value"))

#if (!$_PropertyTool.isNull($department))
  $department.value
#end

or for multiple values:

#set ($departments = $_XPathTool.selectNodes($page, "//dynamic-metadata[name='department']/value"))

#if (!$_PropertyTool.isNull($departments) && $departments.size() > 0)
  #foreach($department in $departments)
    $department.value
  #end
#end

With our API

If you're using our API, you can use .getDynamicField() to set your variables. Example:

#set ($department = $currentPage.metadata.getDynamicField('department'))

#if (!$_PropertyTool.isNull($department))
  $department.value
#end

or for multiple values:

#set ($department = $currentPage.metadata.getDynamicField('department'))

#if (!$_PropertyTool.isNull($department) && !$_PropertyTool.isEmpty($department.values[0]))
  #foreach($department in $department.values)
    $department
  #end
#end
Did this answer your question?