Search code examples
springspring-mvcspring-bootthymeleaf

Thymleaf - how to call model Attribute on html document


Im trying to render a webapge and use the thymleaf attribute "url" added with model.addAttribute but the Attribute is not beeing displayed on the html document.
My document.html file path is here:

/templates/webpage/document.html

@RequestMapping(value = "/webpage/document")
    public String document(HttpServletRequest req, Model model) {

        model.addAttribute("dialogurl", url);
        return "/webpage/document";
    }

Here is the html document

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:include="wrapperdialog :: page">
<head>
    <title></title>
</head>
<body>
<div th:fragment="content">
    <div class="container dialogpage">
        <div class="row">
            <div class="col-md-12">
                <div id="typeform" th:attr="data-url=*{dialogurl}">
                </div>
            </div>
        </div>
    </div>
</div>

Solution

  • Please use this expression to bind dialog url: @{${dialogurl}}

    <div id="typeform" th:attr="data-url=@{${dialogurl}}">
    

    @ prefix is used to specify a link and $ prefix is used to bind your model value.