<% 
 let data = {
    "getPrescriptionsByPatient": [
      {
        "id": "10124680",
        "idType": "SPL_HB_PRESCRIPTION_ID_TYPE",
        "isReadyFill": true,
        "isRefillEligible": true,
        "mdoFlag": false,
        "drugInfo": {
          "drug": {
            "ndcId": "00003052811",
            "name": "SPRYCEL 50MG TABS"
          },
          "ancillaryProductIndicator": "false"
        },
        "patient": {
          "id": "7324859",
          "idType": "SPL_HB_PATIENT_ID_TYPE"
        },
        "fills": [
          {
            "fillNumber": 0,
            "isInitialFill": false
          }
        ]
      }
    ]
  }
%>



{

    "contents": {

    "intent": {

      "content": {

        "elements": [

          {

            "elements": [

              <% for (let i of data.getPrescriptionsByPatient) { %>

              {

                "action": "app://app.com/dialog/selectedintent?value=<%= i.drugInfo.drug.name %>&metadata=<%= i.id %>",             

                "fillNumber": "<%= i.fills.fillNumber %>",

                "rxNumber": "<%= i.id %>",

                "ancillaryProductIndicator": "<%= i.drugInfo.ancillaryProductIndicator %>",

                "firstFillIndicator": "<%= i.fills.isInitialFill %>",

                "style": "left",

                "ndcid": "<%= i.drugInfo.drug.ndcId %>",

                "textValue": "<%= i.drugInfo.drug.name %>"

              }<% if (data.getPrescriptionsByPatient.indexOf(i) !== data.getPrescriptionsByPatient.length - 1) { %>,<% } %>

              <% } %>

            ],

            "minSelection": 1,

            "minSelectionErrorMessages": "Minimum one prescription should be selected",

            "objectType": "checkboxgroup",

            "style": "vertical",

            "submitButton": {

              "action": "app://app.com/chat/submitintent?value=I%20want%20to%20refill%20%24selection%24%20prescriptions",

              "style": "filled",

              "textValue": "Refill the selected Prescriptions"

            }

          },

          {

            "action": "app://app.com/chat/submitintent?value=I%20want%20to%20refill%20all%20my%20prescriptions",

            "objectType": "button",

            "style": "filled",

            "textValue": "Refill all the prescriptions"

          },

          {

            "action": "app://app.com/chat/submitintent?value=None%20of%20the%20above",

            "objectType": "button",

            "style": "text",

            "textValue": "I don't see the prescription in the above listed"

          }

        ],

        "objectType": "group",

        "style": "vertical"

      }

    },

    "message": {

      "content": {

        "objectType": "text",

        "style": "body",

        "value": "You have <%= data.getPrescriptionsByPatient.length %> prescriptions eligible for refill. Please select from the list below."

      }

    }

  },

  "statusCode": "0000",

  "statusDescription": "Success"

} 

EJS online compiler

Write, Run & Share EJS templates online using OneCompiler’s EJS online compiler for free. It’s a minimal yet powerful online playground for rendering dynamic HTML using Embedded JavaScript (EJS). Getting started with OneCompiler’s EJS editor is quick and easy. You get a sample boilerplate EJS code with every new session.

About EJS

EJS (Embedded JavaScript templating) is a simple templating language that lets you generate HTML markup with plain JavaScript. It is commonly used in Node.js applications, especially with Express, to render views on the server side.

EJS syntax allows embedding JavaScript logic directly within HTML using <% %> delimiters.

Sample Code

The following is a sample EJS template that displays a personalized greeting:

<%
 let message = 'Hello, World!'
%>
<%= message %>

Syntax Basics

Output Data

  • <%= %> — Outputs the value into the template (escaped)
  • <%- %> — Outputs unescaped HTML
<p>Hello, <%= user.name %>!</p>
<%- include('footer') %>

Control Flow

  • <% %> — Executes JavaScript logic without output
<% if (user.isLoggedIn) { %>
  <p>Welcome, <%= user.name %>!</p>
<% } else { %>
  <p>Please log in.</p>
<% } %>

Loops

<ul>
<% items.forEach(function(item) { %>
  <li><%= item %></li>
<% }); %>
</ul>

Partials (Includes)

<%- include('header') %>
<main>
  Content goes here
</main>
<%- include('footer') %>

This guide provides a quick reference to EJS templating syntax and usage. Start writing and rendering EJS code with OneCompiler’s EJS online compiler today!