Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:31:51+00:00 2026-06-13T05:31:51+00:00

I wrote a custom template engine to let me use my old templates in

  • 0

I wrote a custom template engine to let me use my old templates in a rewrite of my current project. Everything is working except that Express.js always sends a

Error: Failed to lookup view (template name)

I have multiple templates in one file and I don’t need one file for each template. But how can I tell that to Express?

I can’t get my head around this.
Any help is appreciated

EDIT: Some Code:

My Express Setup: (app.js)

var express = require('express');
var app = express();
var gclosure = require('./templateEngine');
var fs = require('fs');

/**
 * Setup Express
 */
app.configure(function(){

    app.engine('test', gclosure.__express);

    app.set('views', __dirname + '/public/templates');
    app.set('view engine', 'test');

    app.use(express.favicon());
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.methodOverride());

    app.use(require('less-middleware')({
        src: __dirname + '/public'
    }));

    app.use(express.static(__dirname + '/public'));
});

My Custom Template Engine (templateEngine.js)

exports.renderFile =  function(path, options, fn){

  if ('function' == typeof options) {
    fn = options, options = {};
  }

  try {

    fm(null, "This is a test output");

  } catch (err) {
    fn(err);
  }
};

My test route in express:

  app.get('/', function(req, res, next) {

    res.render('simple',{
              title: 'Sources',
              data: 'lala',
              options: 'miep'
          }); 

  });

The Clue is: When I create a file named simple.test in the template folder everything is working and I can see the test output string. When I change the name to something that doesn’t exist the out put is

Error: Failed to lookup view (template name)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:31:52+00:00Added an answer on June 13, 2026 at 5:31 am

    The problem:

    Express uses the template engine to create a view object which renders the view. Since the view itself is created by looking up the file into the filesystem the template engine has no way of telling express that it handles the files on its own.

    The Solution:

    Instead of using a template engine approach I wrote a custom middle-ware that intercepts calls to my template engine depending on the name of the template function. Basically I overwrite the response.render() function in express.


    Update: GitHub Repo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrote a custom MultipleChoiceField. I have everything working ok but when I
I wrote custom Twig loader that fetch templates from database and it works in
I'm trying to write a custom rendering template for use in the DisplayForm of
i wrote a custom jquery function that accept a callback but not being able
I wrote a custom wordpress plugin that is shown in the left menu bar
I have created a Custom List Template and wrote the Schema.xml,feature to deploy it,Installed
I am trying to write a template custom control in C#, ASP.NET that will
I wrote my own custom page template for my Wordpress page, now I want
I use some third-party template tags in my Django Application (maintained elsewhere) that return
I'm at a point in my custom view engine that I want things to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.