Search code examples
htmljqueryspringthymeleafboot

show container while passing attribute from spring boot


How can I solve this?

            <div th:if="${showContent}=='true'" id="container-two" >
            
             <div class="container-linux">  
        <div><img class="col"
    style="width:50px;" src="" th:src="@{/images/linux.png}" alt=""><br> 
            <label >VM Name is</label>
            <a style="font-weight: bold;" th:text="${vmnameshowlinux}" ></a><br>
            <label >VM IpAddress is</label>
            <a  style="font-weight: bold;" th:text="${ipaddresslinux}" ></a></div>
            <a th:href="@{/launchconsole}" class="btn btn-success">Launch RDP</a>
                </div>
            <div class="container-windows"> 
    <div><img class="col"
            style="width:50px;" src="" th:src="@{/images/windows.png}" alt=""><br> 
            <label >VM Name is</label>
            <a style="font-weight: bold;" th:text="${vmnameshowwin}" ></a><br>
            <label >VM IpAddress is</label>
            <a  style="font-weight: bold;" th:text="${ipaddresswin}" ></a></div>
            
            <a th:href="@{/launchconsole}" class="btn btn-success">Launch RDP</a>
            </div>
                </div>








`
String showContent="true";
modelandview.addObject("showContent", showContent);

`

i want to show container-two by passing the true value in the showContent object in spring boot thymeleaf project


Solution

  • You should pass a regular boolean:

    boolean showContent = true;
    modelandview.addObject("showContent", showContent);
    

    And then Thymeleaf should look like:

    <div th:if="${showContent}" id="container-two" >
      .
      .
      .
    </div>