EJS Templating





Profound.js API, the HTML Container widget, and the AJAX Container widget allow for the use of EJS, a syntax that supports dynamic JavaScript templating code embedded within HTML.

This capability provides for a simple implementation of custom dynamic HTML output, including features like:

  • Responsive Design

  • Easier integration with other JavaScript and CSS frameworks, such as Bootstrap

  • Rendering subfile information using an alternate view, such as an Unordered List (UL) or a TABLE in HTML

  • Multiple pieces of information that flow, instead of being positioned absolutely

EJS provides special tags that can be used within the HTML:

  • <% 'Scriptlet' tag, for control-flow, no output

  • <%_ 'Whitespace Slurping' Scriptlet tag, strips all whitespace before it

  • <%= Outputs the value into the template (HTML escaped)

  • <%- Outputs the unescaped value into the template

  • <%# Comment tag, no execution, no output

  • <%% Outputs a literal '<%'

  • %%> Outputs a literal '%>'

  • %> Plain ending tag

  • -%> Trim-mode ('newline slurp') tag, trims following newline

  • _%> 'Whitespace Slurping' ending tag, removes all whitespace after it

The following JavaScript variables are inherently available within EJS:

  • Any bound field name on the screen

  • Numeric indicators are accessible as flags[xx], where xx is the name of the indicator. For example, flags[99] would access *IN99.

  • Subfile record information as an array of records or objects having properties that match the bound fields names defined within the subfile

The field names and subfile record names can be referenced using all lower case or all upper case.



Example 1:

The following will show 2 fields (LASTNAME and FIRSTNAME) flowing one after the other regardless of the width of any field's contents.

First, add an HTML Container widget. Bind the "user defined data" property to the LASTNAME field. Bind the "user defined data 2" property to the FIRSTNAME field. Then, put the following code into the "html" property:

<%= LASTNAME.trim() %>, <%= FIRSTNAME %>



Example 2:

The following will show a subfile as an HTML table:

Add a Subfile Grid widget. Add fields named LASTNAME and FIRSTNAME into the grid. Name the grid record format "SFL". Then, hide the grid.

Then add an HTML Container widget and put the following code into the "html" property:

<table width="100%" border="1"> <tr> <th>Last Name</th> <th>First Name</th> </tr> <% for (i = 0; i < sfl.length; i++) { %> <tr> <td> <%= sfl[i].LASTNAME %> </td> <td> <%= sfl[i].FIRSTNAME %> </td> </tr> <% } %> </table>



Example 3:

The following will show a subfile as an Unordered List:

Add a Subfile Grid widget. Add fields named FIRSTNAME and LASTNAME into the grid. Name the grid record format "SFL". Then, hide the grid.

Then add an HTML Container widget and put the following code into the "html" property:

<ul> <% for (i = 0; i < sfl.length; i++) { %> <li> <%= sfl[i].FIRSTNAME.trim() + ' ' + sfl[i].LASTNAME.trim() %> </li> <% } %> </ul>