{"id":1355,"date":"2008-09-12T03:45:23","date_gmt":"2008-09-12T08:45:23","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/docs\/?page_id=1355"},"modified":"2025-07-28T11:35:36","modified_gmt":"2025-07-28T16:35:36","slug":"freemarker-overview","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/freemarker-overview","title":{"rendered":"Freemarker Overview"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">A Brief Explanation<\/h4>\n\n\n\n<p>In all templates, m-Power uses the Freemarker template engine to create your Java Servlet Applications. While Freemarker itself is not a &#8220;complete&#8221; coding language, it is quite powerful and rich with many customizable options.<\/p>\n\n\n\n<p>When you generate any m-Power application, you will see code similar to this in the source of your HTML:<\/p>\n\n\n\n<p><code>&lt;!-- &lt;#list table_rows as row&gt; --&gt;<\/code><\/p>\n\n\n\n<p><code>&lt;tr&gt; &lt;td nowrap class=\"${rowClass(row_index)}\" align=\"right\"&gt;<\/code><\/p>\n\n\n\n<p><code>${row.CUSNO?html}<\/code><\/p>\n\n\n\n<p><code>&lt;\/td&gt;&lt;td nowrap class=\"${rowClass(row_index)}\" align=\"right\"&gt;<\/code><\/p>\n\n\n\n<p><code>${row.CMPNO?html}<\/code><\/p>\n\n\n\n<p><code>&lt;\/td&gt;&lt;td nowrap class=\"${rowClass(row_index)}\" align=\"left\"&gt;<\/code><\/p>\n\n\n\n<p><code>${row.CNAME?html}<\/code><\/p>\n\n\n\n<p><code>&lt;\/td&gt; &lt;\/tr&gt;<\/code><\/p>\n\n\n\n<p><code>&lt;!-- &lt;\/#list&gt; --&gt;<\/code><\/p>\n\n\n\n<p>The first and last lines of the code #list and \/#list dictate to your Java Servlet to repeat this section of code for as many records as are requested to be displayed on the screen.<\/p>\n\n\n\n<p>Within m-Power, fields are noted: ${row.CMPNO?html} where CMPNO is the name of your Field. The $ denotes that a Substitution is about to occur. {row. Indicates the location the field is to come from. Alternatives to the {row. Syntax would be row0.FIELDNAME for Single Record Templates, and ${grandTotal, ${subTotal1, ${subTotal2 for Reports. The CMPNO indicates the name of the Field from your Database. Lastly, the ?html indicates the field&#8217;s encoding.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">Any code outside of the &lt;#list&gt; and &lt;\/#list&gt; tags will only be preformed once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Basic Coding with Freemarker within Presentation (HTML) Layer<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><em>Creating New Variables<\/em><\/h4>\n\n\n\n<p>Freemarker structure is fully customizable to include some coding placed directly within the presentation (HTML) layer. To assign a variable, use the following syntax:<\/p>\n\n\n\n<p><code>&lt;!--&lt;#assign variablename=value&gt;--&gt;<\/code><\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">For computability reasons within m-Painter, you must wrap all #assign tags within HTML comment tags.<\/p>\n\n\n\n<p>Examples of the #assign tag.<\/p>\n\n\n\n<p><code>&lt;!--&lt;#assign counter=0&gt;--&gt;<\/code><\/p>\n\n\n\n<p><code>&lt;!--&lt;#assign counter=counter+1&gt;--&gt;<\/code><\/p>\n\n\n\n<p><code>&lt;!--&lt;#assign sometext=\"Sample Text\"&gt;--&gt;<\/code><\/p>\n\n\n\n<p>To use these variables, simply use the following text: ${counter} where counter is your newly created variable name. <\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">Variables created on the page should <strong>not <\/strong>include &#8220;row.&#8221; in the syntax as these values are not coming from the database.<\/p>\n\n\n\n<p>If you wish to create a variable and assign a value from your database, please use the following syntax:<\/p>\n\n\n\n<p><code>&lt;!--&lt;#assign sometext= row.FIELDNAME&gt;--&gt;<\/code> <\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-danger\">Including the &#8220;$&#8221;, curly brackets, and &#8220;row.&#8221; within a freemarker function will cause a runtime error. Instead of using ${row.FIELDNAME}, just use row.FIELDNAME<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><em>If &amp; If\/Else Looping<\/em><\/h4>\n\n\n\n<p>You can also utilize looping within the HTML layer as well. The syntax is as follows:<\/p>\n\n\n\n<p><code>&lt;!--&lt;#if variable RELATIONSHIP value&gt;--&gt;<\/code> <\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">For computability reasons within m-Painter, you must wrap all #if tags within HTML comment tags.<\/p>\n\n\n\n<p>Code inside If statement<\/p>\n\n\n\n<p><code>&lt;!--&lt;\/#if&gt;--&gt;<\/code><\/p>\n\n\n\n<p>Valid relationships include all standard relationships, including:<\/p>\n\n\n\n<p>== &#8212; Equals<\/p>\n\n\n\n<p>&gt; &#8212; Greater than<\/p>\n\n\n\n<p>&gt;= &#8212; Greater than or Equal to<\/p>\n\n\n\n<p>&lt; &#8212; Less than<\/p>\n\n\n\n<p>&lt; &#8212; Less than or Equal to<\/p>\n\n\n\n<p>!= &#8212; Not equal to<\/p>\n\n\n\n<p>You can also use Else logic as well:<\/p>\n\n\n\n<p><code>&lt;!--&lt;#if variable == 0&gt;--&gt;<\/code><\/p>\n\n\n\n<p><code>&lt;!--&lt;#assign variable=7&gt;--&gt;<\/code><\/p>\n\n\n\n<p>Variable is equal to 7<\/p>\n\n\n\n<p><code>&lt;!--&lt;#else&gt;--&gt;<\/code> <\/p>\n\n\n\n<p>Variable is equal to 0<\/p>\n\n\n\n<p><code>&lt;!--&lt;\/#if&gt;--&gt;<\/code><\/p>\n\n\n\n<p>If you wish to use a Database value within your IF statement, please use the following syntax:<\/p>\n\n\n\n<p><code>&lt;!--#if sometext== row.FIELDNAME&gt;--&gt;<\/code> <\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><em>Common Variables<\/em><\/h4>\n\n\n\n<p>${visitor.user} &#8212; Only available when mrc Security has been activated. Will display the User&#8217;s Sign on name.<\/p>\n\n\n\n<p>${visitor.library} &#8212; Will return the name of the Current Data Dictionary.<\/p>\n\n\n\n<p>${page.app} &#8212; Will return the Application name. For instance, Report 10 would return R00010.<\/p>\n\n\n\n<p>${visitor.sessionID} &#8212; Will return the 32 character Session ID. This ID is unique by Browser Session, thus no two browsers can have the same session ID.<\/p>\n\n\n\n<p>${visitor.remoteIp} &#8212; This variable will return the IP address of the Client&#8217;s browser.<\/p>\n\n\n\n<p>${visitor.loginDate} &#8212; This variable will return the Date of the Initial login. It is in the format YYYY-MM-DD. In the absence of mrc Security, it will display the time the application was first accessed.<\/p>\n\n\n\n<p>${visitor.loginTime} &#8212; This variable will return the Time of the Initial login. It is in the format HH:MM:SS. In the absence of mrc Security, it will display the time the application was first accessed.<\/p>\n\n\n\n<p>${visitor.userAgent} &#8212; This variable will return the full User Agent string from the client&#8217;s browser.<\/p>\n\n\n\n<p id=\"FMDates\"><em>Common Date Variables<\/em><br>All values are returned in the YYYY-MM-DD format. Variables that return a range are separated by a space. Fiscal dates are determined from the &#8216;fiscal_month&#8217; setting in the mrcjava\/WEB-INF\/classes\/mrc_runtime.properties file (i.e. fiscal_month=5).<\/p>\n\n\n\n<p>Assuming the current date is 2018-01-10, the date variables would return the following values:<\/p>\n\n\n\n<p>${visitor.today} &#8212; Current date (2018-01-10)<br>${visitor.tomorrow} &#8212; Tomorrow&#8217;s date (2018-01-10)<br>${visitor.yesterday} &#8212; Yesterday&#8217;s date (2018-01-09)<br>${visitor.thisweek} &#8212; Sunday to Saturday of the current week (2018-01-07 2018-01-13)<br>${visitor.thisweektodate} &#8212; Sunday of the current week to the current date (2018-01-07 2018-01-10)<br>${visitor.lastweektodate} &#8212; Sunday of the previous week to the current week day of the previous week (2017-12-31 2018-01-03)<br>${visitor.lastweek} &#8212; Sunday and Saturday of the previous week (2017-12-31 2018-01-06)<br>${visitor.nextweek} &#8212; Sunday to Saturday of the following week (2018-01-14 2018-01-20)<br>${visitor.thismonth} &#8212; First day of the current month to the last day of the current month (2018-01-01 2018-01-31)<br>${visitor.thismonthtodate} &#8212; First day of the current month to the current day of the current month (2018-01-01 2018-01-10)<br>${visitor.nextmonth} &#8212; First day of the following month to the last day of the following month (2018-02-01 2018-02-28)<br>${visitor.lastmonth} &#8212; First day of the previous month to the last day of the previous month (2017-12-01 2017-12-31)<br>${visitor.lastmonthtodate} &#8212; First day of the previous month to the current day of the previous month (2017-12-01 2017-12-10)<br>${visitor.thisquarter} &#8212; First day of the current quarter to the last day of the current quarter (2018-01-01 2018-03-31)<br>${visitor.lastquarter} &#8212; First day of the previous quarter to the last day of the previous quarter (2017-10-01 2017-12-31)<br>${visitor.thisyear} &#8212; First day of the current year to the last day of the current year (2018-01-01 2018-12-31)<br>${visitor.nextyear} &#8212; First day of the following year to the last day of the following year (2019-01-01 2019-12-31)<br>${visitor.lastyear} &#8212; First day of the previous year to the last day of the previous year (2017-01-01 2017-12-31)<br>${visitor.thisyeartodate} &#8212; First day of the current year to the current date (2018-01-01 2018-01-10)<br>${visitor.lastyeartodate} &#8212; First day of the previous year to the current day of the previous year (2017-01-01 2017-01-10)<br>${visitor.thisquarterfiscal} &#8212; First day of the current fiscal quarter to the last day of the current fiscal quarter (2017-11-01 2018-01-31)<br>${visitor.lastquarterfiscal} &#8212; First day of the previous fiscal quarter to the last day of the previous fiscal quarter (2017-08-01 2017-10-31)<br>${visitor.thisyearfiscal} &#8212; First day of the current fiscal year to the last day of the current fiscal year (2017-05-01 2018-04-30)<br>${visitor.lastyearfiscal} &#8212; First day of the previous fiscal year to the last day of the previous fiscal year (2016-05-01 2017-04-30)<br>${visitor.thisyearfiscaltodate} &#8212; First day of the current fiscal year to the current date (2017-05-01 2018-01-10)<br>${visitor.lastyearfiscaltodate} &#8212; First day of the previous fiscal year to the current day of the previous fiscal year (2016-05-01 2017-01-10)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How to Implement your own Freemarker Custom Changes<\/strong><\/h3>\n\n\n\n<p>To make Freemarker changes, compile your application and enter m-Painter. Click the &#8220;Source&#8221; button and find your <code>&lt;#list&gt;<\/code> section using m-Painter&#8217;s Binoculars. It is at this location within the code that you can make all necessary changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Links to Useful Freemarker Resources<\/strong><\/h3>\n\n\n\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/docs\/freemarker\/string-functions-within-freemarker\" target=\"_blank\" rel=\"noopener noreferrer\">Useful Freemarker String Functions<\/a><\/p>\n\n\n\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/docs\/freemarker\/numeric-functions-within-freemarker\" target=\"_blank\" rel=\"noopener noreferrer\">Useful Freemarker Numeric Functions<\/a><\/p>\n\n\n\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/date-functions-within-freemarker\">Useful Freemarker Date Functions<\/a><\/p>\n\n\n\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/docs\/freemarker\/using-freemarker-to-control-the-layout-of-rows\" target=\"_blank\" rel=\"noopener noreferrer\">Controlling Page Layout using If Logic<\/a><\/p>\n\n\n\n<p>&#8212; <a href=\"https:\/\/freemarker.apache.org\/docs\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">Freemarker Site<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Brief Explanation In all templates, m-Power uses the Freemarker template engine to create your Java Servlet Applications. While Freemarker itself is not a &#8220;complete&#8221; coding language, it is quite powerful and rich with many customizable options. When you generate any m-Power application, you will see code similar to this&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[265],"ht-kb-tag":[],"class_list":["post-1355","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-freemarker"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/comments?post=1355"}],"version-history":[{"count":18,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1355\/revisions"}],"predecessor-version":[{"id":14641,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1355\/revisions\/14641"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/media?parent=1355"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-category?post=1355"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-tag?post=1355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}