| <!doctype html> |
| <!-- Generated by FreeMarker/Docgen from DocBook --> |
| <html lang="en" class="page-type-section"> |
| <head prefix="og: http://ogp.me/ns#"> |
| <meta charset="utf-8"> |
| <title>Old-style macro and call directives - FreeMarker Manual</title> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| <meta name="format-detection" content="telephone=no"> |
| <meta property="og:site_name" content="FreeMarker Manual"> |
| <meta property="og:title" content="Old-style macro and call directives"> |
| <meta property="og:locale" content="en_US"> |
| <meta property="og:url" content="http://example.com/ref_depr_oldmacro.html"> |
| <link rel="canonical" href="http://example.com/ref_depr_oldmacro.html"> |
| <link rel="icon" href="favicon.png" type="image/png"> |
| <link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1594338517553"> |
| </head> |
| <body itemscope itemtype="https://schema.org/Code"> |
| <meta itemprop="url" content="http://example.com/"> |
| <meta itemprop="name" content="FreeMarker Manual"> |
| |
| <!--[if lte IE 9]> |
| <div style="background-color: #C00; color: #fff; padding: 12px 24px;">Please use a modern browser to view this website.</div> |
| <![endif]--><div class="header-top-bg"><div class="site-width header-top"><a class="logo" href="http://example.com" role="banner"> <img itemprop="image" src="logo.png" alt="My Logo"> |
| </a></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">FreeMarker Manual</a><div class="navigation-header"></div></div><div class="site-width breadcrumb-row"><ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref.html"><span itemprop="name">Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_deprecated.html"><span itemprop="name">Deprecated FTL constructs</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_depr_oldmacro.html"><span itemprop="name">Old-style macro and call directives</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="ref.html">Reference</a></li><li><a href="app_faq.html">FAQ</a></li><li><a href="preface.html#test_target">Bőregér</a></li></ul></div></div></div> <div class="main-content site-width"> |
| <div class="content-wrapper no-toc"> |
| <div id="table-of-contents-wrapper" class="col-left"> |
| </div> |
| <div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="ref_depr_builtin.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_depr_transform.html"><span>Next</span></a></div><div class="title-wrapper"> |
| <h1 class="content-header header-section1" id="ref_depr_oldmacro" itemprop="headline">Old-style macro and call directives</h1> |
| </div></div><div class="page-menu"> |
| <div class="page-menu-title">Page Contents</div> |
| <ul><li><a class="page-menu-link" href="#autoid_127" data-menu-target="autoid_127">Synopsis</a></li><li><a class="page-menu-link" href="#autoid_128" data-menu-target="autoid_128">Description</a></li></ul> </div><a name="ref.directive.oldmacro"></a><a name="ref.directive.call"></a> |
| |
| |
| |
| |
| <h2 class="content-header header-section2" id="autoid_127">Synopsis</h2> |
| |
| |
| |
| <pre class="metaTemplate"><code class="inline-code"><#macro <em class="code-color">name</em>(<em class="code-color">argName1</em>, <em class="code-color">argName2</em>, <em class="code-color">... argNameN</em>)> |
| ... |
| </#macro></code> |
| |
| <code class="inline-code"><#call <em class="code-color">name</em>(<em class="code-color">argValue1</em>, <em class="code-color">argValue2</em>, <em class="code-color">... argValueN</em>)></code></pre> |
| |
| |
| <p>Where:</p> |
| |
| <ul> |
| <li> |
| <code class="inline-code"><em class="code-color">name</em></code>: name |
| of the macro (not expression) |
| </li> |
| |
| <li> |
| <code class="inline-code"><em class="code-color">argName1</em></code>, |
| <code class="inline-code"><em class="code-color">argName2</em></code>, ...etc.: |
| the name of the <a href="dgui_misc_var.html">local |
| variables</a> store the parameter values (not |
| expression) |
| </li> |
| |
| <li> |
| <code class="inline-code"><em class="code-color">argValue1</em></code>, |
| <code class="inline-code"><em class="code-color">argValue2</em></code>, |
| ...etc.: expressions, the value of the parameters |
| </li> |
| </ul> |
| |
| |
| |
| |
| |
| <h2 class="content-header header-section2" id="autoid_128">Description</h2> |
| |
| |
| <div class="callout note"> |
| <strong class="callout-label">Note:</strong> |
| |
| <p>This is the documentation of FreeMarker 2.1 macro and macro |
| related directives. These are still working, but deprecated. You |
| may want to read the FreeMarker 2.2+ references: <a href="ref_directive_macro.html#ref.directive.macro">macro, return</a>, <a href="ref_directive_userDefined.html#ref.directive.userDefined">user-defined directive |
| call</a></p> |
| </div> |
| |
| |
| <p>A macro is a template fragment with an associated name. You |
| can use that named fragment on multiple places in your template, so |
| it helps in repetitive tasks. A macro can have parameters that |
| influence the output generated when you use the macro.</p> |
| |
| <p>You define a macro with the <code class="inline-code">macro</code> |
| directive, and then you can use the defined macro in the whole |
| template. The <code class="inline-code">macro</code> directive itself does not |
| write anything to the output, it just defines the macro. For example |
| this will define a macro called <code class="inline-code">warning</code>:</p> |
| |
| |
| |
| <div class="code-wrapper"><pre class="code-block code-template"><strong><#macro warning(message)></strong> |
| <div align=center> |
| <table border=1 bgcolor=yellow width="80%"><tr><td align=center> |
| <b>Warning!</b> |
| <p>${message} |
| </td></tr></table> |
| </div> |
| <strong></#macro></strong></pre></div> |
| |
| <p>The macro definition body (the section between the macro |
| start-tag and end-tag) will be processed whenever you use the |
| <code class="inline-code">call</code> directive with the name of the macro. For |
| example this calls the macro called |
| <code class="inline-code">warning</code>:</p> |
| |
| |
| |
| <div class="code-wrapper"><pre class="code-block code-template"><#call warning("Unplug the machine before opening the cover!")></pre></div> |
| |
| <p>and will write this to the output:</p> |
| |
| |
| |
| <div class="code-wrapper"><pre class="code-block code-output"> <div align=center> |
| <table border=1 bgcolor=yellow width="80%"><tr><td align=center> |
| <b>Warning!</b> |
| <p>Unplug the machine before opening the cover! |
| </td></tr></table> |
| </div> |
| </pre></div> |
| |
| <p>The parameters passed in as parameters to the |
| <code class="inline-code">call</code> directive will be accessible in the macro |
| definition body as <a href="dgui_misc_var.html">local |
| variables</a>.</p> |
| |
| <p>When you call a macro, you must specify the same number of |
| parameters as were specified in the macro definition. For example if |
| this is the macro definition:</p> |
| |
| |
| |
| <div class="code-wrapper"><pre class="code-block code-template"><#macro test(a, b, c)>Nothing...</#macro></pre></div> |
| |
| <p>then these are valid macro calls:</p> |
| |
| |
| |
| <div class="code-wrapper"><pre class="code-block code-template"><#call test(1, 2, 3)> |
| <#call test("one", 2 + x, [1234, 2341, 3412, 4123])></pre></div> |
| |
| <p>If a macro has no parameters, then you can omit the |
| parentheses:</p> |
| |
| |
| |
| <div class="code-wrapper"><pre class="code-block code-template"><#macro test>mooo</#macro> |
| <#call test></pre></div> |
| |
| <p>When you define a macro it will be available in the template, |
| where you have defined it only. But probably you want to use the |
| same macros in more templates. In this case you can store your macro |
| definitions in a common file, and then include that file in all |
| templates where you need those macros.</p> |
| |
| <p>It's fine to call a macro that's defined further down in the |
| template <span class="marked-for-programmers">(since macros are defined at |
| parse time, not in process time)</span>. However, if the macro |
| definitions are inserted with <code class="inline-code">include</code> directive, |
| they will not be available until FreeMarker has executed the |
| <code class="inline-code">include</code> directive.</p> |
| |
| <p>You can leave a macro definition body before the |
| <code class="inline-code"></#macro></code> tag with the |
| <code class="inline-code">return</code> directive.</p> |
| <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_depr_builtin.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_depr_transform.html"><span>Next</span></a></div></div></div></div> </div> |
| </div> |
| <div class="site-footer"><div class="site-width"><div class="footer-bottom"> <p class="last-generated"> |
| Last generated: |
| <time itemprop="dateModified" datetime="2020-07-09T23:48:37Z" title="Thursday, July 9, 2020 11:48:37 PM GMT">2020-07-09 23:48:37 GMT</time> </p> |
| <p class="copyright"> |
| © <span itemprop="copyrightYear">1999</span>–2020 |
| <a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="https://apache.org/">The Apache Software Foundation</a> </p> |
| </div></div></div></body> |
| </html> |