Import one FTL file inside another FTL file

淺唱寂寞╮ 提交于 2019-12-29 06:43:37

问题


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

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


回答1:


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>

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 /> 

Macros are a great feature in FreeMarker and can be parameterized as well - they can really cut down on code duplication in your templates.




回答2:


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 "deepak.ftl"> will work if both the FTL files are in the same directory. You may use relative paths if they're not.



来源:https://stackoverflow.com/questions/6040047/import-one-ftl-file-inside-another-ftl-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!