Closed DjebbZ closed 12 years ago
This bug appear in new version of express. The field that contains local variables was rename to _locals
. I have fix it in version 0.3.2.
{{{ yield }}}
— is the place where your page are rendered inside the layout, see picture below
Thank you, I couldn't figure that out. Seeing the picture, it means that there can be just one layout per page, but multiple partials right ?
No, you can have one layout for many pages.
You have one common layout, like this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello, world!</title>
</head>
<body>
{{{ yield }}}
</body>
</html>
and when you want to render index page, you write res.render("index");
, that takes you default layout, and replace {{{ yield }}}
with content of index.html:
<p>I'm a index.html</p>
when you want render other page, with same layout, for example, about page, you write res.render("about");
, that takes you default layout, and replace {{{ yield }}}
with content of about.html:
<p>I'm a about.html</p>
If you want render page with custom layout, just specify it in options res.render("admin.html", {layout: "admin-layout"});
This is what I meant, in fact :) A "final" page (the one sent to the client) can only use one layout, which may be different according to the page served. Thanks for the detailed answer.
Thanks for questions, I will update README
Hi,
I'm new to Express, and I'm playing with Express 3. Since Express 3 dropped layouts/templates/partials/whatever support, it seems to be a mess in the community, everyone comes with its own "hack" to make it work with his preferred templating solution. I decided to use yours, since I like hogan/mustache syntax, and since your solution works out of the box.
Unfortunately it doesn't work for me. Layouts work fine, but local variables don't. I'm following closely your example, and when I set something in
res.local
it just doesn't show up in my template and appear as an empty string, with no error at all. Also, your example shows the use of{{{ yield }}}
, but I have no idea whatyield
is since it's neither in your code nor in mustache docs...Here's my code, hoping you can correct me (it's a very WIP) :
from app.js :
routes.js :
layout.html :
index.html :
test.html :
Any help truly appreciated.