{"id":1355,"date":"2008-09-12T03:45:23","date_gmt":"2008-09-12T08:45:23","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/legacy\/?page_id=1355"},"modified":"2020-04-08T10:09:00","modified_gmt":"2020-04-08T15:09:00","slug":"freemarker-overview","status":"publish","type":"page","link":"https:\/\/www.mrc-productivity.com\/legacy\/freemarker\/freemarker-overview","title":{"rendered":"Freemarker Overview"},"content":{"rendered":"<p><!-- Begin Content --><\/p>\n<h1>Freemarker Overview<\/h1>\n<p>&nbsp;<\/p>\n<p>In all templates, m-Power uses the Freemarker template engine to create your Java Servlet Applications.  While Freemarker itself is not a &quot;complete&quot; coding language, it is quite powerful and rich with many customizable options.<\/p>\n<p>When you generate any m-Power application, you will see code similar to this in the source of your HTML:<\/p>\n<p><code>&lt;!-- &lt;#list table_rows as row&gt; --&gt;<\/code><\/p>\n<p><code>&lt;tr&gt; &lt;td nowrap class=\"${rowClass(row_index)}\" align=\"right\"&gt;<\/code><\/p>\n<p><code>${row.CUSNO?html}<\/code><\/p>\n<p><code>&lt;\/td&gt;&lt;td nowrap class=\"${rowClass(row_index)}\" align=\"right\"&gt;<\/code><\/p>\n<p><code>${row.CMPNO?html}<\/code><\/p>\n<p><code>&lt;\/td&gt;&lt;td nowrap class=\"${rowClass(row_index)}\" align=\"left\"&gt;<\/code><\/p>\n<p><code>${row.CNAME?html}<\/code><\/p>\n<p><code>&lt;\/td&gt; &lt;\/tr&gt;<\/code><\/p>\n<p><code>&lt;!-- &lt;\/#list&gt; --&gt;<\/code><\/p>\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<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&#39;s encoding.<\/p>\n<p><strong>Note:<\/strong> Any code outside of the &lt;#list&gt; and &lt;\/#list&gt; tags will only be preformed once.<\/p>\n<p><strong>Basic Coding with Freemarker within Presentation (HTML) Layer<\/strong><\/p>\n<p><em>Creating New Variables<\/em><\/p>\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<p><code>&lt;!--&lt;#assign variablename=value&gt;--&gt;<\/code><\/p>\n<p><strong>Note:<\/strong> For computability reasons within m-Painter, you must wrap all #assign tags within HTML comment tags.<\/p>\n<p>Examples of the #assign tag.<\/p>\n<p><code>&lt;!--&lt;#assign counter=0&gt;--&gt;<\/code><\/p>\n<p><code>&lt;!--&lt;#assign counter=counter+1&gt;--&gt;<\/code><\/p>\n<p><code>&lt;!--&lt;#assign sometext=\"Sample Text\"&gt;--&gt;<\/code><\/p>\n<p>To use these variables, simply use the following text: ${counter} where counter is your newly created variable name.  <strong>Note:<\/strong> There is no &quot;row.&quot; logic.<\/p>\n<p>If you wish to create a variable and assign a value from your database, please use the following syntax:<\/p>\n<p><code>&lt;!--&lt;#assign sometext= row.FIELDNAME&gt;--&gt;<\/code> <strong>Note:<\/strong> Using ${row.FIELDNAME} will cause a Run-Time Error.<\/p>\n<p><em>If &amp; If\/Else Looping<\/em><\/p>\n<p>You can also utilize looping within the HTML layer as well.  The syntax is as follows:<\/p>\n<p><code>&lt;!--&lt;#if variable RELATIONSHIP value&gt;--&gt;<\/code> <strong>Note:<\/strong> For computability reasons within m-Painter, you must wrap all #if tags within HTML comment tags.<\/p>\n<p>Code inside If statement<\/p>\n<p><code>&lt;!--&lt;\/#if&gt;--&gt;<\/code><\/p>\n<p>Valid relationships include all standard relationships, including:<\/p>\n<p>== &#8212; Equals<\/p>\n<p>&gt; &#8212; Greater than<\/p>\n<p>&gt;= &#8212; Greater than or Equal to<\/p>\n<p>&lt; &#8212; Less than<\/p>\n<p>&lt; &#8212; Less than or Equal to<\/p>\n<p>!= &#8212; Not equal to<\/p>\n<p>You can also use Else logic as well:<\/p>\n<p><code>&lt;!--&lt;#if variable == 0&gt;--&gt;<\/code><\/p>\n<p><code>&lt;!--&lt;#assign variable=7&gt;--&gt;<\/code><\/p>\n<p>Variable is equal to 7<\/p>\n<p><code>&lt;!--&lt;#else&gt;--&gt;<\/code> <strong>Note:<\/strong> For computability reasons within m-Painter, you must wrap all #else tags within HTML comment tags.<\/p>\n<p>Variable is equal to 0<\/p>\n<p><code>&lt;!--&lt;\/#if&gt;--&gt;<\/code><\/p>\n<p>If you wish to use a Database value within your IF statement, please use the following syntax:<\/p>\n<p><code>&lt;!--#if sometext== row.FIELDNAME&gt;--&gt;<\/code> <strong>Note:<\/strong> Using ${row.FIELDNAME} will cause a Run-Time Error.<\/p>\n<p><em>Common Variables<\/em><\/p>\n<p>${visitor.user} &#8212; Only available when mrc Security has been activated.  Will display the User&#39;s Sign on name.<\/p>\n<p>${visitor.library} &#8212; Will return the name of the Current Data Dictionary.<\/p>\n<p>${visitor.appName} &#8212; Will return the Application name.  For instance, Report 10 would return R00010, unless specifically changed within the Application Defaults screen.<\/p>\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<p>${visitor.remoteIp} &#8212; This variable will return the IP address of the Client&#39;s browser.<\/p>\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<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<p>${visitor.userAgent} &#8212; This variable will return the full User Agent string from the client&#39;s browser.<\/p>\n<p id=\"FMDates\"><em>Common Date Variables<\/em><br \/>\nAll 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 &#39;fiscal_month&#39; setting in the mrcjava\/WEB-INF\/classes\/mrc_runtime.properties file (i.e. fiscal_month=5).<\/p>\n<p>Assuming the current date is 2018-01-10, the date variables would return the following values:<\/p>\n<p>${visitor.today} &#8212; Current date (2018-01-10)<br \/>\n${visitor.tomorrow} &#8212; Tomorrow&#39;s date (2018-01-10)<br \/>\n${visitor.yesterday} &#8212; Yesterday&#39;s date (2018-01-09)<br \/>\n${visitor.thisweek} &#8212; Sunday to Saturday of the current week (2018-01-07 2018-01-13)<br \/>\n${visitor.thisweektodate} &#8212; Sunday of the current week to the current date (2018-01-07 2018-01-10)<br \/>\n${visitor.lastweektodate} &#8212; Sunday of the previous week to the current week day of the previous week (2017-12-31 2018-01-03)<br \/>\n${visitor.lastweek} &#8212; Sunday and Saturday of the previous week (2017-12-31 2018-01-06)<br \/>\n${visitor.nextweek} &#8212; Sunday to Saturday of the following week (2018-01-14 2018-01-20)<br \/>\n${visitor.thismonth} &#8212; First day of the current month to the last day of the current month (2018-01-01 2018-01-31)<br \/>\n${visitor.thismonthtodate} &#8212; First day of the current month to the current day of the current month (2018-01-01 2018-01-10)<br \/>\n${visitor.nextmonth} &#8212; First day of the following month to the last day of the following month (2018-02-01 2018-02-28)<br \/>\n${visitor.lastmonth} &#8212; First day of the previous month to the last day of the previous month (2017-12-01 2017-12-31)<br \/>\n${visitor.lastmonthtodate} &#8212; First day of the previous month to the current day of the previous month (2017-12-01 2017-12-10)<br \/>\n${visitor.thisquarter} &#8212; First day of the current quarter to the last day of the current quarter (2018-01-01 2018-03-31)<br \/>\n${visitor.lastquarter} &#8212; First day of the previous quarter to the last day of the previous quarter (2017-10-01 2017-12-31)<br \/>\n${visitor.thisyear} &#8212; First day of the current year to the last day of the current year (2018-01-01 2018-12-31)<br \/>\n${visitor.nextyear} &#8212; First day of the following year to the last day of the following year (2019-01-01 2019-12-31)<br \/>\n${visitor.lastyear} &#8212; First day of the previous year to the last day of the previous year (2017-01-01 2017-12-31)<br \/>\n${visitor.thisyeartodate} &#8212; First day of the current year to the current date (2018-01-01 2018-01-10)<br \/>\n${visitor.lastyeartodate} &#8212; First day of the previous year to the current day of the previous year (2017-01-01 2017-01-10)<br \/>\n${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 \/>\n${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 \/>\n${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 \/>\n${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 \/>\n${visitor.thisyearfiscaltodate} &#8212; First day of the current fiscal year to the current date (2017-05-01 2018-01-10)<br \/>\n${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<p><strong>How to Implement your own Freemarker Custom Changes<\/strong><\/p>\n<p>To make Freemarker changes, compile your application and enter m-Painter.  Click the &quot;Source&quot; button and find your <code>&lt;#list&gt;<\/code> section using m-Painter&#39;s Binoculars.  It is at this location within the code that you can make all necessary changes.<\/p>\n<p><strong>Links to Useful Freemarker Resources<\/strong><\/p>\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/legacy\/freemarker\/string-functions-within-freemarker\" target=\"_blank\" rel=\"noopener noreferrer\">Useful Freemarker String Functions<\/a><\/p>\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/legacy\/freemarker\/numeric-functions-within-freemarker\" target=\"_blank\" rel=\"noopener noreferrer\">Useful Freemarker Numeric Functions<\/a><\/p>\n<p>&#8212; <a href=\"https:\/\/www.mrc-productivity.com\/legacy\/freemarker\/using-freemarker-to-control-the-layout-of-rows\" target=\"_blank\" rel=\"noopener noreferrer\">Controlling Page Layout using If Logic<\/a><\/p>\n<p>&#8212; <a href=\"https:\/\/freemarker.apache.org\/legacy\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">Freemarker Site<\/a><\/p>\n<p><!-- End Content --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Freemarker Overview &nbsp; In all templates, m-Power uses the Freemarker template engine to create your Java Servlet Applications. While Freemarker itself is not a &quot;complete&quot; 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 in the source of your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1352,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1355","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/comments?post=1355"}],"version-history":[{"count":12,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1355\/revisions"}],"predecessor-version":[{"id":9540,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1355\/revisions\/9540"}],"up":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/pages\/1352"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/legacy\/wp-json\/wp\/v2\/media?parent=1355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}