data/authors/Paul Logan.json

Native Javascript Templating

Javascript Frameworks & Libraries

My first experience of Javascript libraries was with Knockout and I loved it. It became a major part of the main SAAS software project I worked on at the time.

My second experience was with (ReactJs)[] - I tried it out on a handful of data maintenance screens in an internal web app. These screens would not be used by many people apart from IT, so they provided a good testing area. I enjoyed learning a new technology (who doesn’t), and appreciated the itch it was scratching.

However, the learning curve was steep. The Babel requirement for transpiling the React code caused me some issues when I returned later to the codebase to find that the version of Babel needed to be upgraded.

The inconvenience caused by using React was enough for me to decide to rip it out.

In my search for an alternative, I came across this article - which described exactly the pain I felt from using React. And Jim presented a brilliant, lightweight, easy to understand solution - plain old, native Javascript template literals.

At its simplest:

<!DOCTYPE html>
<html lang="en">

    <title>Native Javascript Templating</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width">
    <link rel="manifest" href="/app.webmanifest">
    <link rel="stylesheet" type="text/css" href="/public/css/site.css" />
    <section id="app">
        <main style="text-align: center;">
			<input id="POnumber"/>
            <section id="PurchaseOrderLines">

		//Listen for user inputting a PO Number
		document.getElementById("POnumber").addEventListener("change", evt => {
			var poNumber =;

			//Request PO information from web server,
			var poLines = StockSystem.getPurchaseOrder(poNumber);

			//Pass PO JSON data to function that returns a string of HTML
			var htmlString = DisplayPoLines(poLines);

			//"Inject" the HTML into the DOM
			document.getElementById("PurchaseOrderLines").innerHTML = htmlString;
		function DisplayPoLines(items) {
			var header = `
					<section class="records">
						<label>Supp Code</label>
						<label>Our Code</label>

			var html = =>
				<section class="records zebraStripe" data-line-id="${item.LineID}">
					<span class="itemCode">${item.ItemCode}</span>
					<input class="qtyRecd" type='number' value='${item.Qty}' min="0" />
			return header + html;