【问题标题】:Import one FTL file inside another FTL file在另一个 FTL 文件中导入一个 FTL 文件
【发布时间】:2011-08-27 18:10:48
【问题描述】:

我已经在 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>

如何在另一个 FTL 文件中使用这个 div

【问题讨论】:

    标签: java spring-mvc freemarker


    【解决方案1】:

    如果您只想将一个 freemarker 模板中的 div 包含在另一个 freemarker 模板中,您可以通过using a macro 提取公共 div。例如,

    in macros.ftl:
    <#macro filterReportDiv>
        <div id="filterReportParameters" style="display:none">
          <form ...>
        ..
          </form>
        </div>
     </#macro>
    

    然后在您的两个 freemarker 模板中,您可以导入 macros.ftl 并通过以下方式调用宏:

    <#import "/path/to/macros.ftl" as m>
    <@m.filterReportDiv /> 
    

    宏是 FreeMarker 中的一个很棒的功能,并且可以参数化 - 它们可以真正减少模板中的代码重复。

    【讨论】:

    【解决方案2】:

    听起来您正在寻找 &lt;#include&gt; 指令 - Freemarker 将处理包含的文件,就好像它是包含文件的一部分一样。

    &lt;#include "deepak.ftl"&gt; 将在两个 FTL 文件位于同一目录中时起作用。如果不是,您可以使用相对路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-31
      • 2010-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      相关资源
      最近更新 更多