Skip to the content.

Suppose you want to list out each day of the week in the markup rendered by Dompiler. You can do so with this JavaScript (which you’ll place in a file called app.js):

// Import Dompiler.
import Dompiler from "../../library/dompiler.js";

// Initialize Dompiler.
let {
} = new Dompiler().withBinding();

// Variables.
let days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ];

// Compile markup string into a document fragment.
let markup = `
        <p>Days of the week:</p>
            ${each(days, (day, index) => `
                    Day ${ index + 1 } of the week is "${ day }".
    compiled = compile(markup);

// Append compiled markup to container.
let container = document.querySelector(".example-container");

The each function in Dompiler allows you to create markup for each element in an array. It also includes the index of the item in the array.

Note that Dompiler places no limitation on the type of values in the array. While string is being used in this case, the array can contain objects of any type.

The markup would look something like this:

<!DOCTYPE html>
    <title>Dompiler Example</title>
    <div class="example-container"></div>
    <script src="app.js" type="module"></script>

You can see a live example here: