8000 GitHub - mengxy/stache: mustache templating for your express apps · GitHub
[go: up one dir, main page]

Skip to content
mengxyPublic
forked from fat/stache

About

mustache templating for your express apps

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stache

Stache is mustache.js for your node express apps.

stache

Whuuuuuut?

Getting this junk running is SUPER easy! check the deets below...

setting it up

first...

npm install stache

Now, when you're configuring your express app, just add this little code in somewhere near the top:

app.set('view engine', 'mustache')
app.register(".mustache", require('stache'));

BOOOM! you're all set!

how to actually use it

render your views with res.render...

app.get('/', function (req, res) {
  res.render("index", {
    locals: {
      title: req.params.what
    },
    partials: {
      heading: '<title>{{title}}</title>'
    }
  });
});

Notice you can pass local vars here as well as partials to your templates.

Layouts

Stache supports layouts! swaggg! Which means you can have something like this:

<!-- layout.mustache -->
<html>
<head>
  {{>scripts}}
</head>
<body>
  {{{yield}}}
</body>
</html>

Note: yield is a special local var, which will be replaced automatically by the template you specified with res.render.

Partials

Looking at the example above, check out that partial 54FC reference for scripts!! If when calling your res.render method you don't explicitly specify a script partial, stache will automatically check your views directory for a script.mustache to load as a partial. Pretty boss huh?

What? I still don't get it...

No worries player, check the examples folder for a fully functional example.

shoutout

major props to donpark (hbs), bitdrift, and obviously mustache.js

About

mustache templating for your express apps

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0