Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I render partials with jade without express.js?

Only info I found was this:

http://forrst.com/posts/Node_js_Jade_Import_Jade_File-CZW

I replicated the suggested folder structure (views/partials) But it didn't work, as soon as I put

!=partial('header', {})
!=partial('menu', {})

into index.jade, I get a blank screen, the error message I receive from jade is:

ReferenceError: ./views/index.jade:3 1. 'p index'
2. ''
3. '!=partial(\'header', {})'

partial is not defined

I'd be very grateful for any help ! (I strongly prefer not to use express.js)

like image 947
Blub Avatar asked Apr 23 '11 14:04

Blub


4 Answers

Jade has a command called include. Just use

include _form

given that the filename of the partial is *_form.jade*, and is in the same directory

like image 167
Wilhelm Avatar answered Nov 01 '22 04:11

Wilhelm


As of August 2012 (possibly earlier) Partials have been removed from Express.

A lot of tutorials are now out of date. It seems that you can replicate much of the partial functionality with include.

Eg.

movies.jade

div(id='movies')
  - each movie in movies
    include movie

movie.jade

h2= movie.title
.description= movie.description

HTH

like image 33
Ali W Avatar answered Nov 01 '22 04:11

Ali W


With the latest node/express I get the following movies.jade template to call partials:

div(id='movies')
  - each movie in movies
    !=partial('movie', movie)

where I have movie.jade in the views directory alongside movies.jade.

movies.jade is called from app.js with:

res.render('movies', { movies: [{ title: 'Jaws' }, { title: 'Un Chien Andalou' }] });

like image 30
Thomas David Baker Avatar answered Nov 01 '22 02:11

Thomas David Baker


I think partial rendering is done in express, so you will have to snag that code or write your own.

I have my own helper class for jade rendering with partials that you can use or get some ideas from here, (it's using Joose and Cactus)

like image 36
Adam Bergmark Avatar answered Nov 01 '22 02:11

Adam Bergmark