java 在另一个 FTL 文件中导入一个 FTL 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6040047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import one FTL file inside another FTL file
提问by Deepak Kumar
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
我在 FTL 文件中创建了一个 DIV 并且该 DIV 包含表单现在说我有另一个 FTL 文件,我想在第二个 FTL 文件中使用第一个 FTL 的 div 这可能吗
deepak.ftl
深度文件
<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>
How do i use this div in another FTL file
我如何在另一个 FTL 文件中使用这个 div
回答by A Lee
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,
如果您只想将一个 freemarker 模板中的 div 包含在另一个 freemarker 模板中,您可以使用宏提取公共 div 。例如,
in macros.ftl:
<#macro filterReportDiv>
<div id="filterReportParameters" style="display:none">
<form ...>
..
</form>
</div>
</#macro>
Then in both your freemarker templates, you can import macros.ftl
and invoke the macro via something like:
然后在您的两个 freemarker 模板中,您可以通过以下方式导入macros.ftl
和调用宏:
<#import "/path/to/macros.ftl" as m>
<@m.filterReportDiv />
Macros are a great feature in FreeMarker and can be parameterized as well - they can really cut down on code duplication in your templates.
宏是 FreeMarker 中的一个很棒的功能,也可以参数化 - 它们可以真正减少模板中的代码重复。
回答by no.good.at.coding
It sounds like you're looking for the <#include>
directive - the included file will be processed by Freemarker as though it was part of the including file.
听起来您正在寻找<#include>
指令 - 包含的文件将由 Freemarker 处理,就好像它是包含文件的一部分一样。
<#include "deepak.ftl">
will work if both the FTL files are in the same directory. You may use relative paths if they're not.
<#include "deepak.ftl">
如果两个 FTL 文件都在同一目录中,则将起作用。如果不是,您可以使用相对路径。