1.0.4 • Published 2 years ago

better-ejs v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Better-Ejs:

npm.io

Not fully ready to use

Install:

npm install better-ejs

How to use:

index.js:

const app = express();
const { engine: bjs } = require('better-ejs');

/*Tell express about better-ejs*/
bjs(app);
/*Set the default express view engine to better-ejs*/
app.set('view engine', 'bjs');

app.get('/:user?', (req, res) => {
  const user = req.params.user | 'No One';
  res.render('index', { user });
});

app.listen(3000, () => console.log('[Port]:', 3000));

views/index.bjs

<body>
  {{ include("./components/navbar.bjs", { user }); }}
  <h1>Home<h1>
  <h2>User: <a href="#">{{ out(user) }}</a></h2>
  <h3>
  {{
    if (user === "admin")
    {
      out("It's an admin !");
    }
    else out("It's not and admin !");
  }}
  <h3>
</body>

views/components/navbar.bjs

<nav>
  <h1>
    NavBar: 
    {{
      if (user) {
        out(user)     
      } else {
        out("<a href='/login'>Login</a>");
      }
    }}
  </h1>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/contacts">Contacts</a></li>
    <li><a href="/about">About</a></li>
  </ul>
</nav>

Documentation

out(...data:string): To output something to the Html Document

Known Issues

  • Remove the access to variables defined in the compiler/index.ts file to the user to prevent future problems
1.0.4

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago