Skip to content

Instantly share code, notes, and snippets.

@robpataki
Created April 17, 2019 15:36
Show Gist options
  • Save robpataki/c7ab4c577491d1e7d14914ef50648ab0 to your computer and use it in GitHub Desktop.
Save robpataki/c7ab4c577491d1e7d14914ef50648ab0 to your computer and use it in GitHub Desktop.
Thymeleaf hashmap examples - only saving it here so I don't have to ever think about it again :)
<!-- Define a hashmap -->
<ol class="app-task-list">
<th:block th:with="tasks=${ {{enabled: false, url: '', taskState: 'COMPLETED', titleCode: 'taskList.pre.section.checkEligibility'}} }">
<th:block th:replace="~{ fragments/task-list :: task-list-group(${tasks}, #{taskList.pre.section.title}, 1)}" />
</th:block>
<th:block th:replace="~{ fragments/task-list :: task-list-group(${tasks}, #{taskList.application.section.title}, 2)}" />
<th:block th:replace="~{ fragments/task-list :: task-list-group(${tasks}, #{taskList.apply.section.title}, 3)}" />
</ol>
<!-- Conditional CSS class append using Hashmap lookup -->
<th:block th:fragment="task-list-status-tag(taskState, id)">
<th:block th:with="tagCSSSuffixes=${ {NOT_STARTED:'not-started', IN_PROGRESS:'in-progress', COMPLETED:'completed'} }">
<strong class="app-task-list__task-tag" th:classappend="'app-task-list__task-tag--' + ${tagCSSSuffixes.get(#strings.toString(taskState))}" th:text="#{'taskList.task.state.' + ${#strings.toString(taskState)}}" th:id="${id}"></strong>
</th:block>
</th:block>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment