Skip to content

Instantly share code, notes, and snippets.

@ederrafo
Last active July 8, 2024 01:33
Show Gist options
  • Save ederrafo/3f37c7b346bc7ed9eb241139cc51cfef to your computer and use it in GitHub Desktop.
Save ederrafo/3f37c7b346bc7ed9eb241139cc51cfef to your computer and use it in GitHub Desktop.
thymeleaf breadcrumb
<nav aria-label="breadcrumb">
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active" aria-current="page" th:each="breadcrumb, i : ${breadcrumbs}" >
                <th:block th:switch="${breadcrumb.last}">
                  <th:block th:case="true"> <span th:text="${breadcrumb.name}"></span></th:block>
                  <th:block th:case="false"><a th:href="${breadcrumb.href}" th:text="${breadcrumb.name}">name</a></th:block>
                </th:block>
              </li>
            </ol>
          </nav>
          
          List<Breadcrumb> breadcrumbs = new ArrayList<>();
        Breadcrumb breadcrumb = new Breadcrumb();
        breadcrumb.setLast(false);
        breadcrumb.setName("Oficinas");
        breadcrumb.setHref("/offices");
        breadcrumbs.add(breadcrumb);
        breadcrumb = new Breadcrumb();
        breadcrumb.setLast(true);
        breadcrumb.setName("Nueva Oficina");
        breadcrumbs.add(breadcrumb);
        model.addAttribute("breadcrumbs", breadcrumbs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment