deligenius / view-engine

🚀A Template View Engine for Deno frameworks
MIT License
54 stars 16 forks source link

EJS template Include statement fails to locate file #10

Closed jpeterse closed 4 years ago

jpeterse commented 4 years ago

Using <%- include("header") %> in a template fails to resolve and load the partial template file and return error:

ejs:8
    6|   </head>
    7|   <body>
 >> 8|     <%- include('header') %>
    9|     Hobbies of <%=data.name%>
    10|   </body>
    11| </html>

Could not find the include file "header"

for debugging purposes, I placed all files in the root directory, rather than the conventional ./views and ./views/partials folders.

./app.ts

import { Application } from "https://deno.land/x/oak/mod.ts";
import {
  viewEngine,
  engineFactory,
  adapterFactory,
} from "https://deno.land/x/view_engine/mod.ts";

const ejsEngine = engineFactory.getEjsEngine();
const oakAdapter = adapterFactory.getOakAdapter();

const app: Application = new Application();

app.use( viewEngine( oakAdapter, ejsEngine, {
  viewRoot: '.',
  viewExt: '.ejs'
}));

app.use(async (ctx, next) => {
  ctx.render("index", { data: { name: "John" } });
});

await app.listen({ port: 8000 });

./index.ejs:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <%- include('header') %>
    Hobbies of <%=data.name%>
  </body>
</html>

./header.ejs:

<h3>User Info</h3>
gjuoun commented 4 years ago

Fixed at https://github.com/deligenius/view-engine/releases/tag/v1.2.0