0

Hello!

Is there any way to have the master page or layout in jshtml?

I tried do this in .net Razor style, but it did't works. Link to jshtml view engine.

My intention is to have mastarpage lets say is called layout.jshtml and some other subpages like index.jshtml and so on, like it is in razor.

More explanation of what I mean speaking "I would like have masterpage" I have Layout.jshtml , this is my masterpage

<html>
<head>
    <link rel="stylesheet" href="/stylesheets/style.css" ></link>

</head>
<body>

@writeBody();




</body>
</html>

and I have other view called some.jshtml

<h1>@locals.title</h1>
<div class="Mydata">
@locals.content
@locals.otherContent
</div>

When I run this page in browser I would like to have concatenation of layout.jshtml and some.jshtml. The content of some.jshtml is rendered in writeBody(); in layout.jshtml

When I speaking of concatenation I mean someThing like this. This is result that I can see in browser.

<html>
<head>
    <link rel="stylesheet" href="/stylesheets/style.css" ></link>

</head>
<body>

<h1>title</h1>
<div class="Mydata">
content
otherContent
</div>

</body>
</html>
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
Konrad
  • 726
  • 4
  • 17
  • 33

2 Answers2

0

The jshtml repo links to the jshtml-express project.

The docs there give an example of how to use this in your project :

var express = require('express');

var port = parseInt(process.argv.pop());
var app = express();
app.configure(function() {
    app.use(express.bodyParser());
    app.use(app.router);
});

app.engine('jshtml', require('jshtml-express'));  // make sure you have installed via npm install jshtml-express
app.set('view engine', 'jshtml');

I have not used this myself, but the process is similar with other templating systems (Jade, Handlebars, etc).

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
  • Hello Nick, thanks for Your reply, yes i have installed jshtml-express by npm , and add the lines of code You mentioned, furthermore I have ability to run *.jshtml files to show my data. But I dont know how to setup my app to have masterpage. – Konrad Apr 22 '13 at 18:34
  • Gotcha, I think i'm a little unclear on what you mean by masterpage. Could you give some more detail on that? – Nick Tomlin Apr 22 '13 at 20:00
0

More explanation of what I mean speaking "I would like have masterpage" I have Layout.jshtml , this is my masterpage

<html>
<head>
    <link rel="stylesheet" href="/stylesheets/style.css" ></link>

</head>
<body>

@writeBody();




</body>
</html>

and I have other view called some.jshtml

<h1>@locals.title</h1>
<div class="Mydata">
@locals.content
@locals.otherContent
</div>

When I run this page in browser I would like to have concatenation of layout.jshtml and some.jshtml. The content of some.jshtml is rendered in writeBody(); in layout.jshtml

When I speaking of concatenation I mean someThing like this. This is result that I can see in browser.

<html>
<head>
    <link rel="stylesheet" href="/stylesheets/style.css" ></link>

</head>
<body>

<h1>title</h1>
<div class="Mydata">
content
otherContent
</div>

</body>
</html>
Konrad
  • 726
  • 4
  • 17
  • 33