@macchiatojs/views
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@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

Package Sidebar

Install

npm i @macchiatojs/views

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

10.9 kB

Total Files

6

Last publish

Collaborators

  • 3imed-jaberi