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

  • Home
  • SEARCH
  • 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 6565429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:05:36+00:00 2026-05-25T14:05:36+00:00

I have a simple page with head, menu, content and footer. I need to

  • 0

I have a simple page with head, menu, content and footer. I need to divide them into separate files. After reading through express documentation i (created 4 templates and) wrote something like this:

app.get('/', function(req, res) {
    var response = [null, null, null, null]
    , everyNotNull = function(elem) {
        return (elem !== null);
    }, sendResponse = function(type, str) {
        switch (type) {
            case 'head' : response[0] = str; break;
            case 'menu' : response[1] = str; break;
            case 'content' : response[2] = str; break;
            case 'footer' : response[3] = str; break;
        }

        if (response.every(everyNotNull)) {
            res.send(response.join(''));
        }
    };

    res.partial('head', {'title' : 'page title'}, function(err, str) {
        sendResponse('head', str);
    });

    res.partial('menu', {'active' : '/'}, function(err, str) {
        sendResponse('menu', str);
    });

    res.partial('index', {'title' : 'Home'}, function(err, str) {
        sendResponse('content', str);
    });

    res.partial('footer', {'nowdate' : (new Date()).getFullYear()}, function(err, str) {
        sendResponse('footer', str);
    });
});

Though it works it seems a bit dirty to me. Is there a better way to use partial templates?

  • 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-05-25T14:05:36+00:00Added an answer on May 25, 2026 at 2:05 pm

    You were right to suspect something was missing, you’re doing unnecessary work there.

    Express will stitch the templates together for you, just call res.render() and the name of the view you want to call. The layout and partials should get pulled in automatically.

    In my apps I usually use partials as below. Just replace references to EJS with whichever template engine you’re using (Jade, moustache, etc):

    ./lib/app.js

    app.get('/', function(req, res) {
        var model = {
            layout:'customLayout', // defaults to layout.(ejs|jade|whatever)
            locals:{
                foo:'bar'
            }
        };
        res.render('index',model);
    });
    

    ./views/layout.ejs

    <html>
        <head><%- partial('partials/head') %></head>
        <body>
    <%- partial('partials/menu') %>
    <%- body %>
    <%- partial('partials/footer') %>
        </body>
    </html>
    

    ./views/index.ejs

    <h1>Index page</h1>
    

    ./views/partials/menu.ejs

    <div><a href='... </div>
    

    ./views/partials/head.ejs

    <script>...</script>
    etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple lift page: <html> <head></head> <body> <span id=content class=lift:GetContent></span> </body> </html>
I have a simple HTML-page with a UTF-8 encoded link. <html> <head> <meta http-equiv="content-type"
I have a simple web page that till now didn't need any login. It
I have simple html page and need to post data (title/text) from that page
I have very simple html page with js code: <html> <head> <title></title> </head> <body>
Problem: I have a master page dictating the css, html, head, body content so
I have a simple page that I need to execute some GWO & GATC
I have a simple page that I need to open the print dialog on
I have this very simple page: <html> <head> </head> <body>Handling... <script> var token =
I have created a simple flash menu and the SWF file, JS files (swfoject.js

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.