Jade模板无法正确呈现javascript

时间:2015-01-22 00:17:14

标签: node.js templates express pug

我有一个关于从块中包含脚本的问题

来自快递 - 发电机,

layout.jade

doctype html
html
    head
        title= title
        link(rel='stylesheet', href='/stylesheets/style.css')
    body
        block content
        include sidebar
    script(src='/javascripts/jquery.js')
    block bottomscripts

sidebar.jade

block bottomscripts
    script(src='/javascripts/sidebar.js')

输出

<html>
    <head>
        <title>Express</title>
        <link rel="stylesheet" href="/stylesheets/style.css">
      </head>
      <body>
        <h1>Express</h1>
        <p>Welcome to Express</p>
        <script src="/javascripts/sidebar.js">
        </script><script src="/javascripts/jquery.js"></script>
      </body>
</html>

我怎样才能将sidebar.js移到jquery.js下面?我需要在sidebar.jade

内完成

谢谢

2 个答案:

答案 0 :(得分:0)

你试过在你的街区中加入jquery.js吗?似乎他们都是&#34; bottomscripts&#34;。

block bottomscripts
    script(src='/javascripts/jquery.js')
    script(src='/javascripts/sidebar.js')

答案 1 :(得分:0)

因此可以移动include语句并将jquery sctipt语句的缩进更改为

doctype html
html
    head
        title= title
        link(rel='stylesheet', href='/stylesheets/style.css')
    body
        block content        
        script(src='/javascripts/jquery.js')
        include sidebar
    block bottomscripts

获取

<!DOCTYPE html>
<html>

<head>
  <title></title>
  <link rel="stylesheet" href="/stylesheets/style.css">
</head>

<body>
  <script src="/javascripts/jquery.js"></script>
  <script src="/javascripts/sidebar.js"></script>
</body>

</html>