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

后端 未结 4 1556
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 18:35

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

相关标签:
4条回答
  • 2021-02-20 19:04

    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)

    0 讨论(0)
  • 2021-02-20 19:08

    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

    0 讨论(0)
  • 2021-02-20 19:14

    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' }] });

    0 讨论(0)
  • 2021-02-20 19:15

    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

    0 讨论(0)
提交回复
热议问题