0

I want to pick which jade partial to include by sending the location as a local. Here's what I tried:

app.js:

var express = require('express');
var fs = require('fs');
var app = express();
var jade = require('jade');

app.get('/jadetest', function(req, res){
    var fn = jade.compileFile('views/over.jade');
    var locals = {"bodystring": "./body.jade"}

    res.writeHead(200, {'Content-Type': 'html'});
    res.write(fn(locals));
    res.end();
})

var server = app.listen(3000);

over.jade:

doctype html
html(lang="en")
    head
title= pageTitle
body
    h1 Title
    // This doesn't work
    //include bodystring
    // or this
    //include #{bodystring}
    // or this
    //include -bodystring
    // this does, but it doesn't offer the flexibility I want
    include ./body.jade

body.jade:

h1 Jade - node template engine

I can set the title as the contents of bodystring but it doesn't like it when I put it in an include. Is there a separate syntax for this? Is it possible at all? Am I doing things the hard way?

Nate
  • 85
  • 3
  • 1
    See [Use a variable in a Jade include](http://stackoverflow.com/questions/12132978/use-a-variable-in-a-jade-include) – robertklep Jul 17 '15 at 10:48
  • 1
    Do you mean you want to use a variable after `include`, i.e. dynamic include? [Unfortunately](http://stackoverflow.com/questions/28225921/jade-dynamic-includes-work-around) [it isn't possible](https://github.com/jadejs/jade/issues/1312), or at least not currently. – laggingreflex Jul 18 '15 at 03:27

0 Answers0