Freemarker Overview

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 “complete” 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 HTML:

<!-- <#list table_rows as row> -->

<tr> <td nowrap class="${rowClass(row_index)}" align="right">

${row.CUSNO?html}

</td><td nowrap class="${rowClass(row_index)}" align="right">

${row.CMPNO?html}

</td><td nowrap class="${rowClass(row_index)}" align="left">

${row.CNAME?html}

</td> </tr>

<!-- </#list> -->

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.

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’s encoding.

Any code outside of the <#list> and </#list> tags will only be preformed once.

Basic Coding with Freemarker within Presentation (HTML) Layer

Creating New Variables

Freemarker structure is fully customizable to include some coding placed directly within the presentation (HTML) layer. To assign a variable, use the following syntax:

<!--<#assign variablename=value>-->

For computability reasons within m-Painter, you must wrap all #assign tags within HTML comment tags.

Examples of the #assign tag.

<!--<#assign counter=0>-->

<!--<#assign counter=counter+1>-->

<!--<#assign sometext="Sample Text">-->

To use these variables, simply use the following text: ${counter} where counter is your newly created variable name.

Variables created on the page should not include “row.” in the syntax as these values are not coming from the database.

If you wish to create a variable and assign a value from your database, please use the following syntax:

<!--<#assign sometext= row.FIELDNAME>-->

Including the “$”, curly brackets, and “row.” within a freemarker function will cause a runtime error. Instead of using ${row.FIELDNAME}, just use row.FIELDNAME

If & If/Else Looping

You can also utilize looping within the HTML layer as well. The syntax is as follows:

<!--<#if variable RELATIONSHIP value>-->

For computability reasons within m-Painter, you must wrap all #if tags within HTML comment tags.

Code inside If statement

<!--</#if>-->

Valid relationships include all standard relationships, including:

== — Equals

> — Greater than

>= — Greater than or Equal to

< — Less than

< — Less than or Equal to

!= — Not equal to

You can also use Else logic as well:

<!--<#if variable == 0>-->

<!--<#assign variable=7>-->

Variable is equal to 7

<!--<#else>-->

Variable is equal to 0

<!--</#if>-->

If you wish to use a Database value within your IF statement, please use the following syntax:

<!--#if sometext== row.FIELDNAME>-->

Common Variables

${visitor.user} — Only available when mrc Security has been activated. Will display the User’s Sign on name.

${visitor.library} — Will return the name of the Current Data Dictionary.

${visitor.appName} — Will return the Application name. For instance, Report 10 would return R00010, unless specifically changed within the Application Defaults screen.

${visitor.sessionID} — Will return the 32 character Session ID. This ID is unique by Browser Session, thus no two browsers can have the same session ID.

${visitor.remoteIp} — This variable will return the IP address of the Client’s browser.

${visitor.loginDate} — 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.

${visitor.loginTime} — 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.

${visitor.userAgent} — This variable will return the full User Agent string from the client’s browser.

Common Date Variables
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 ‘fiscal_month’ setting in the mrcjava/WEB-INF/classes/mrc_runtime.properties file (i.e. fiscal_month=5).

Assuming the current date is 2018-01-10, the date variables would return the following values:

${visitor.today} — Current date (2018-01-10)
${visitor.tomorrow} — Tomorrow’s date (2018-01-10)
${visitor.yesterday} — Yesterday’s date (2018-01-09)
${visitor.thisweek} — Sunday to Saturday of the current week (2018-01-07 2018-01-13)
${visitor.thisweektodate} — Sunday of the current week to the current date (2018-01-07 2018-01-10)
${visitor.lastweektodate} — Sunday of the previous week to the current week day of the previous week (2017-12-31 2018-01-03)
${visitor.lastweek} — Sunday and Saturday of the previous week (2017-12-31 2018-01-06)
${visitor.nextweek} — Sunday to Saturday of the following week (2018-01-14 2018-01-20)
${visitor.thismonth} — First day of the current month to the last day of the current month (2018-01-01 2018-01-31)
${visitor.thismonthtodate} — First day of the current month to the current day of the current month (2018-01-01 2018-01-10)
${visitor.nextmonth} — First day of the following month to the last day of the following month (2018-02-01 2018-02-28)
${visitor.lastmonth} — First day of the previous month to the last day of the previous month (2017-12-01 2017-12-31)
${visitor.lastmonthtodate} — First day of the previous month to the current day of the previous month (2017-12-01 2017-12-10)
${visitor.thisquarter} — First day of the current quarter to the last day of the current quarter (2018-01-01 2018-03-31)
${visitor.lastquarter} — First day of the previous quarter to the last day of the previous quarter (2017-10-01 2017-12-31)
${visitor.thisyear} — First day of the current year to the last day of the current year (2018-01-01 2018-12-31)
${visitor.nextyear} — First day of the following year to the last day of the following year (2019-01-01 2019-12-31)
${visitor.lastyear} — First day of the previous year to the last day of the previous year (2017-01-01 2017-12-31)
${visitor.thisyeartodate} — First day of the current year to the current date (2018-01-01 2018-01-10)
${visitor.lastyeartodate} — First day of the previous year to the current day of the previous year (2017-01-01 2017-01-10)
${visitor.thisquarterfiscal} — First day of the current fiscal quarter to the last day of the current fiscal quarter (2017-11-01 2018-01-31)
${visitor.lastquarterfiscal} — First day of the previous fiscal quarter to the last day of the previous fiscal quarter (2017-08-01 2017-10-31)
${visitor.thisyearfiscal} — First day of the current fiscal year to the last day of the current fiscal year (2017-05-01 2018-04-30)
${visitor.lastyearfiscal} — First day of the previous fiscal year to the last day of the previous fiscal year (2016-05-01 2017-04-30)
${visitor.thisyearfiscaltodate} — First day of the current fiscal year to the current date (2017-05-01 2018-01-10)
${visitor.lastyearfiscaltodate} — First day of the previous fiscal year to the current day of the previous fiscal year (2016-05-01 2017-01-10)

How to Implement your own Freemarker Custom Changes

To make Freemarker changes, compile your application and enter m-Painter. Click the “Source” button and find your <#list> section using m-Painter’s Binoculars. It is at this location within the code that you can make all necessary changes.

Useful Freemarker String Functions

Useful Freemarker Numeric Functions

Controlling Page Layout using If Logic

Freemarker Site

Updated on September 30, 2021

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support