在另一个FTL文件中导入一个FTL文件 [英] Import one FTL file inside another FTL file
问题描述
我在FTL文件中创建了一个DIV,DIV包含表单现在说我有另一个FTL文件,我想在第二个FTL文件中使用第一个FTL的div这是可能的
I have created one DIV inside a FTL file and that DIV contain form now say i have another FTL file and i want to use first FTL's div inside second FTL file is this possible
<div id="filterReportParameters" style="display:none">
<form method="POST" action="${rc.getContextPath()}/leave/generateEmpLeaveReport.json" target="_blank">
<table border="0px" class="gtsjq-master-table">
<tr>
<td>From</td>
<input type="hidden" name="empId" id="empId"/>
<td>
<input type="text" id="fromDate" name="fromDate" class="text ui-widget-content ui-corner-all" style="height:20px;width:145px;"/>
</td>
<td>Order By</td>
<td>
<select name="orderBy" id="orderBy">
<option value="0">- - - - - - - Select- - - - - - - -</option>
<option value="1">Date</option>
<option value="2">Leave Type</option>
<option value="3">Transaction Type</option>
</select>
</td>
</tr>
<tr>
<td>To</td>
<td><input type="text" id="toDate" name="toDate" class="text ui-widget-content ui-corner-all" style="height:20px;width:145px;"/>
</tr>
<tr>
<td>Leave Type</td>
<td>
<select name="leaveType" id="leaveType">
<option value="0">- - - - - - - Select- - - - - - - -</option>
<#list leaveType as type>
<option value="${type.id}">${type.leaveType.description}</option>
</#list>
</select>
</td>
</tr>
<tr>
<td>Leave Transaction</td>
<td>
<select name="transactionType" id="transactionType">
<option value="0">- - - - - - - Select- - - - - - - -</option>
<#list leaveTransactionType as leaveTransaction>
<option value="${leaveTransaction.id}">${leaveTransaction.description}</option>
</#list>
</select>
</td>
</tr>
</table>
</form>
我如何使用此div在另一个FTL文件中
How do i use this div in another FTL file
推荐答案
如果您只想将一个freemarker模板中的div包含在另一个freemarker模板中,您可以提取常见的通过使用宏进行分析。例如,
If you just want to include the div from one freemarker template in another freemarker template you can extract the common div out by using a macro. For example,
in macros.ftl:
<#macro filterReportDiv>
<div id="filterReportParameters" style="display:none">
<form ...>
..
</form>
</div>
</#macro>
然后在两个freemarker模板中,您可以导入 macros.ftl
并通过以下方式调用宏:
Then in both your freemarker templates, you can import macros.ftl
and invoke the macro via something like:
<#import "/path/to/macros.ftl" as m>
<@m.filterReportDiv />
宏是FreeMarker中的一个很棒的功能,也可以参数化 - 它们可以真正减少代码模板中的重复。
Macros are a great feature in FreeMarker and can be parameterized as well - they can really cut down on code duplication in your templates.
这篇关于在另一个FTL文件中导入一个FTL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!