Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't 'include' within <head> tags. #176

Closed
robotogre opened this issue May 7, 2014 · 6 comments
Closed

Can't 'include' within <head> tags. #176

robotogre opened this issue May 7, 2014 · 6 comments

Comments

@robotogre
Copy link

If I do the following within index.html:

<head>
     {{ include commonHead.html }}
</head>
<body>
</body>

The rendered version of index.html that is served appears as:

<head>
</head>
<body>
     "    "
     <meta name="viewport" content="width=device-width, initial-scale=1">
<meta
</body>

Two things are wrong:

  1. The included content should have been written inside the 'head' tags. NOT the 'body' tags...
  2. A strange empty string was added after the 'body' tag. : " "

How can I 'include' text inside the 'head' tags? :(

@tj
Copy link
Owner

tj commented May 7, 2014

hmm do you have a snippet that we can reproduce with? there shouldn't be anything content-specific like head tags etc, ejs doesn't care about any of that

@robotogre
Copy link
Author

Wow! Thank you VERY much for replying so incredibly quickly! That is also great news that the error is mine. Since the error is almost certainly mine, I do NOT expect anyone here to assist me. However, if anyone feels generous, here is my app.js:

/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var ejs = require('ejs');

var app = express();

// all environments
app.set('port', process.env.PORT || 9977);
app.engine('html', ejs.renderFile); 
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'));
app.use(express.favicon(path.join(__dirname, 'public/images/all.ico')));
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

 ejs.open = '{{'; 
 ejs.close = '}}';

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/about', routes.about);


http.createServer(app).listen(app.get('port'), function(){

});

And here is my routes/index.js:

/*
 * GET home page.
 */

exports.index = function(req, res){
  res.render('index'); 
};

Please let me know if there is anymore information I can provide. Thanks Again!

@ForbesLindesay
Copy link
Contributor

Is that the actual text output? Or is that what appears in the chrome web-inspector. Often the result of doing a right click then "View Page Source" will give a very different result from the chrome debugger. This happens any time you output html that isn't "valid" as the browsers attempt to compensate and often that means moving elements around in really surprising ways.

@ForbesLindesay
Copy link
Contributor

Also, what's the contents of commonHead.html

@TimothyGu
Copy link

@robotogre Can you answer @ForbesLindesay's two questions? I really want to fix this, so if you are still here please give us enough information to reproduce this bug.

@robotogre
Copy link
Author

Hello! I have searched my computer, but I am unable to find the affected code project files. :(

I would assume that the problem was almost certainly my fault, as I am a total novice with node.js and JavaScript templating engines.

I am extremely impressed with your intent to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants