Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js jade - how do I set the content type in jade

Tags:

node.js

pug

I have a view in which the MIME type returned varies. How do I set the content type in the head section?

Here is what I am trying to do

!!!
html
  head
    title #{site.title} - #{site.version}
    link(rel='stylesheet', href='/stylesheets/style.css')
    script(type='text/javascript', src='/javascripts/jquery-1.5.1.min.js')
    content-type #{mimetype}
  body!= body
like image 740
MattM Avatar asked Sep 17 '11 13:09

MattM


People also ask

How do you set Jade as view engine?

Now, write the following code to render above Jade template using Express. js. var express = require('express'); var app = express(); //set view engine app. set("view engine","jade") app.

How do I run a jade file in node js?

All jade files need to be transformed in the HTML. Also don't forget that you need to install other dependencie like express, nodemailer, etc (see requires in the source code). And the application should by available on http://localhost/3000. All Jade templates will be correctly rendered and displayed as HTML.

Is Jade better than EJS?

EJS is way faster than Jade and handlebars. EJS has a really smart error handling mechanism built right into it. It points out to you, the line numbers on which an error has occurred so that you don't end up looking through the whole template file wasting your time in searching for bugs. Simple template tags: <% %>.

What is Jade template?

Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.


1 Answers

You can specify the content-type meta tag like so:

meta(http-equiv="content-type", content="#{contentType}; charset=UTF-8")

Remember that the tag for content-type is <META ...

like image 89
jcolebrand Avatar answered Sep 28 '22 16:09

jcolebrand