dynamic metadata dropdowns and velocity

lauren.fraser's Avatar

lauren.fraser

30 Jul, 2014 09:30 PM

We have dynamic metadata fields that are a drop down. I'm trying to only show the value if it is not equal to none or blank.

I was trying both and not having luck with either, so I'm open to suggestions if there's a better way to do this.

$hasSpec2 prints none when using the EscapeTool like below. What I'd like it to do is only print the value if something other than none is chosen in the drop down.

$hasSpec3 is showing $_EscapeTool.xml($docsSpecialty3.value) on the page (the first item in the dropdown is a blank field)

#set ($hasSpec2 = $_XPathTool.selectSingleNode($docs,"dynamic-metadata[name='specialty2'][. != 'none']"))
#set ($hasSpec3 = $_XPathTool.selectSingleNode($docs,"dynamic-metadata[name='specialty3'][. != '']"))

<h1>$_SerializerTool.serialize($docsTitle,true)</h1>
<h2><ul style="list-style: none;"><li>$_EscapeTool.xml($docsSpecialty.value) </li>
<li>#if ( $hasSpec2 ) $_EscapeTool.xml($docsSpecialty2.value)#end </li>
<li>#if ( $hasSpec3 ) $_EscapeTool.xml($docsSpecialty3.value)#end</li></ul></h2>
  1. 1 Posted by Ryan Griffith on 31 Jul, 2014 12:35 PM

    Ryan Griffith's Avatar

    Hi Lauren,

    I think you are close, but I believe you may need to tweak your XPath slightly when obtaining the value of the fields.

    #set ($hasSpec2 = $_XPathTool.selectSingleNode($docs,"dynamic-metadata[name='specialty2' and value != 'none']/value"))
    #set ($hasSpec3 = $_XPathTool.selectSingleNode($docs,"dynamic-metadata[name='specialty3' and value != '']/value"))
    

    Another way you could do this is to obtain the value element using the XPath Tool and check it's value within the #if statement:

    #set ($hasSpec2 = $_XPathTool.selectSingleNode($docs,"dynamic-metadata[name='specialty2']/value"))
    #set ($hasSpec3 = $_XPathTool.selectSingleNode($docs,"dynamic-metadata[name='specialty3']/value"))
    
    #if ($hasSpec2 && $hasSpec2.value != "none") ... #end
    #if ($hasSpec3 && $hasSpec3.value != "") ... #end
    

    Note: I did not test these methods out, so let me know if they do not work and I'd be happy to do some additional testing.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by lauren.fraser on 31 Jul, 2014 03:32 PM

    lauren.fraser's Avatar

    Ryan,

    The first one worked. Thanks!

    Lauren

  3. 3 Posted by Ryan Griffith on 31 Jul, 2014 04:17 PM

    Ryan Griffith's Avatar

    Thank you for following up, Lauren. I am glad to hear the first version did the trick.

    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!

  4. Ryan Griffith closed this discussion on 31 Jul, 2014 04:17 PM.

Comments are currently closed for this discussion. You can start a new one.

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