Use hash tables

c-siems's Avatar


02 Aug, 2016 07:53 PM

With the absence of labels in radio-items of data definitions, I wondered if I could use a hash table in Velocity to translate radio-item values into CSS class names?

For example, if the XML is
<category>Security Update</category>

Using key -> value notation, the hash table would be

'Security Update' -> 'update-top-border'

What would the velocity be to output the HTML?

<div class="callout update-top-border" data-equalizer-watch>

  1. 1 Posted by Wing Ming Chan on 02 Aug, 2016 09:47 PM

    Wing Ming Chan's Avatar


    Assuming that you can retrieve the data, say, using the Locator tool, you can create a hashmap in a format, to be included and consumed by another format. See for an example on how to use methods like putAll and get. Also see and for the API documentation.


  2. 2 Posted by Ryan Griffith on 03 Aug, 2016 12:34 PM

    Ryan Griffith's Avatar


    If you're dealing with a small subset and don't mind maintaining the values in an additional place, you can go simple and define your map as such:

    #set ($myHashMap = {
      "Security Update": "update-top-border",
      "Radio Choice": "css-class",

    You would then use that map:

    #set ($radioValue = ...)
    #set ($cssClassName = $myHashMap.get($radioValue))
    #if (!$_PropertyTool.isNull($cssClassName))
      <div class="callout ${cssClassName}" data-equalizer-watch>

    Please let me know if you have any questions.


  3. 3 Posted by c-siems on 03 Aug, 2016 01:21 PM

    c-siems's Avatar

    Wing, thanks for the resources. Your Velocity tutorials are easy enough for me to understand.

    Thanks Ryan, I think that's what I need.

  4. 4 Posted by Ryan Griffith on 03 Aug, 2016 01:28 PM

    Ryan Griffith's Avatar

    Not a problem at all!

    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!

  5. Ryan Griffith closed this discussion on 03 Aug, 2016 01:28 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts


? 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


26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM