我想要创建一个基本片段,我可以从其中插入内容,以确保所有内容都以特定大小为中心。我目前有如下内容:
<div th:fragment="centerColumn(content)" class="columns is-centered">
<div class="column is-three-quarters">
<div th:insert="${content}"></div>
</div>
</div>我会打电话给:
<div th:insert="fragments :: centerColumn( ~{fragments :: couponList(${coupons})} )"></div>在我的index.html里。但是,这只适用于将一个片段传递到另一个片段。我想传递一个html,它不是一个thymeleaf片段,即如下所示的形式:
<body class="has-navbar-fixed-top">
<div th:replace="fragments :: navbar(${loggedIn})">Insert Navbar/Menu here</div>
<div th:replace="fragments :: displayCenter(${displayText})"></div>
<br>
<div th:insert="centerColumn(content)">
<div>form here</div>
</div>
<form method="post">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Submit">
</form>
</body>我不知道如何将表单html传递给传递给centerColumn片段的内容,或者如何将其嵌套在div中。
html元数据:
<!DOCTYPE html>
<html xlmns:th="http://www.thymeleaf.org">
<!-- fragment for the html head tag. Helps with reusability of a css stylesheet provided -->
<head th:fragment="html_head">
<meta charset="ISO-8859-1">
<title>[[${pageTitle}]]</title>
<!-- USE th:text="${pageTitle}" OR [[${pageTitle}]] -->
<!-- pageTitle: GO TO Controller and check Model -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
<style>
.equal-height {
display: flex;
flex-direction: column;
height: 100%;
}
</style>
</head>发布于 2022-11-25 09:52:32
我解决了,但感觉有点烦躁。我将表单放置在被替换的div中,并在div中引用表单的id,并将其作为参数传递给替换div的centerColumn片段。*注册是指以下html所在的文件名
<body class="has-navbar-fixed-top">
<div th:replace="fragments :: navbar(${loggedIn})">Insert Navbar/Menu here</div>
<div th:replace="fragments :: displayCenter(${displayText})"></div>
<br>
<div th:replace="centerColumn(~{signup :: #content})">
<form method="post" id="content">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Submit">
</form>
</div>
</body>https://stackoverflow.com/questions/74568355
复制相似问题