Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append block to parent using jade template

I'm trying to create a modular layout using jade template. I would like to append a script block from a child into its parents parent. I'm not quite sure if its possible at all.

Here is my structure

layout.jade

head.jade

index.jade

users.jade

layout.jade: doctype html#html include head

    body
        block content

head.jade:

head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    block scripts

index.jade:

extends layout

block content
    h1 Hello

    include users

users.jade

block append scripts
    script(src='/javascripts/user.js')  

ul
    each user, i in users
        li(class=i+"-"+user) #{user} 

My desired html output should be:

<!DOCTYPE html>
<html id="html">
    <head>
        <title>Index</title>
        <link href="/stylesheets/style.css" rel="stylesheet">
        <script src="/javascripts/user.js">  <!--// append this from user.jade into head.jade //-->
    </head>
    <body>

        <h1>Hello bob</h1>
        <li class="0-user1">user1</li>
like image 464
Alx Avatar asked Nov 25 '12 13:11

Alx


1 Answers

This should be possible, and there are examples in the jade documentation that do exactly this. Your code all looks fine except you need to indent your script tag in users.jade so it is indented below the block append script directive.

like image 67
Peter Lyons Avatar answered Oct 16 '22 10:10

Peter Lyons