@macchiatojs/views

Macchiato.js view render engine based on ejs.

Usage no npm install needed!

<script type="module">
  import macchiatojsViews from 'https://cdn.skypack.dev/@macchiatojs/views';
</script>

README

@macchiatojs/views

View engine based on ejs help to render content for Macchiato.js

Installation

# npm
$ npm install @macchiatojs/views
# yarn
$ yarn add @macchiatojs/views

Usage

First, you should create a directory in which you have all views templates. You can do it by run this command and make sure your in the source code folder;

mkdir views

Second, you should create a template file. You can do it by run this command;

touch views/home.html

Third, you should put your ejs logic inside the file. something like;

<ul>
  <% users.forEach((user) => {%>
  <li><%= user.name %></li>
  <% })%>
</ul>

Finally, you can use @macchiatojs/views;

import ViewEngine from "@macchiatojs/views";

const viewEngine = new ViewEngine({
  root: path.join(__dirname, "views"),
  viewExt: "html",
});

const htmlString = await viewEngine.generateHtml("home", { users });
// htmlString have a string with this values
// <ul>
//   <li>Jawher</li>
//   <li>Imed</li>
//   <li>Tom</li>
// </ul>

License


MIT © Imed Jaberi