Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express, jade layout file rendering body but not rendering head

My problem is with my jade layout file not rendering correctly. The body is rendered but the head tags in the produced html are empty. I have tried to render the layout.jade file separately and it works perfectly.

Here is my layout.jade file

!!!
html
    head
        title= title
        link(rel='stylesheet', href='stylesheets/style.css')
        script(type='text/javascript', src='javascripts/jquery-1.7.2.js')
        link(rel='stylesheet', href='stylesheets/pictogram-button.css')
body
    header(style='padding-bottom:50px;')
        include partials/header
    section(style='min-height:600px;') 
        div!= body
    footer.footer
        include partials/footer

And here is my index.jade file

.line_h100t
.column_wrap800
    .round_box1_w800
        .list_fl10
            ul.line_h40
                li(style='margin-left:20px;')
                    ul
                        li
                            img(src='/images/icon/whiteWithoutCircle/check.png')
                            img(src='/images/login/loginTxt.png')
                    ul.line_h40t
                        li(style='margin-left:50px;')
                            p 로그인이 필요하신 분은
                            p Oopa Roopa 관리팀으로 문의해 주세요!
                li(style='border-left:1px solid #999; padding:0 0 0 20px;')
                    ul
                        li
                            span.text_yellow ID
                    ul
                        li
                            input.login_input(type='text')
                    ul.line_h35t
                        li
                            span.text_yellow PASSWORD
                    ul
                        li
                            input.login_input(type='password')
                li
                    ul.line_h10t
                        a.button-bevel.transparency(href='#')
                            .line_h35
                                span.lock
                                p(style='width:100px;') LOGIN

And here is the function in my express app that renders the index file.

    adminLogin : function (req,res) {
    res.render( 'index', {
        title: 'Admin Login',
        pageCategory: 'Admin Login',
        pageName : 'index'
    });
},

Thank you in advance for any help you an give me.

like image 469
Kenley Tomlin Avatar asked Aug 11 '12 07:08

Kenley Tomlin


1 Answers

In express 3, layouts were removed in favor of template inheritance as explained here. The jade readme describes how this works, and an additional example is here.

You will need to replace div!= body with block body (or similar). Then at the top of index.jade, you'll want to add extends layout. Finally put the contents of index.jade under a block body (or whatever name you used in layout.jade).

like image 83
David Weldon Avatar answered Nov 04 '22 09:11

David Weldon