最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Jade using Javascript variables - Stack Overflow

programmeradmin4浏览0评论

I have the following example code

extends layout

block append content
 - var user = {name:'hello word'}
 include includes/header
 div.container
  p
   #{user.name}
  #blogs
    - each blog in blogs
      div.blog
         strong
          div.title
             a(href="/blog/"+blog._id)!= blog.title
         small
          div.created_at= blog.created_at
         div.body= blog.body.substring(0,100) + ' ... '
           a(href="/blog/"+blog._id)!= 'Read More'
  include includes/footer

This renders HTML output that contains

<p>
  <hello world><hello>
</p>

Can anyone explain what is going on here according to the Jade tutorial this should render correctly ...

I have the following example code

extends layout

block append content
 - var user = {name:'hello word'}
 include includes/header
 div.container
  p
   #{user.name}
  #blogs
    - each blog in blogs
      div.blog
         strong
          div.title
             a(href="/blog/"+blog._id)!= blog.title
         small
          div.created_at= blog.created_at
         div.body= blog.body.substring(0,100) + ' ... '
           a(href="/blog/"+blog._id)!= 'Read More'
  include includes/footer

This renders HTML output that contains

<p>
  <hello world><hello>
</p>

Can anyone explain what is going on here according to the Jade tutorial this should render correctly ...

Share Improve this question asked Oct 21, 2013 at 12:59 avronoavrono 1,6803 gold badges20 silver badges41 bronze badges 1
  • Depends on what you were expecting the output to be. What would you consider "correct" in this case? – Jonathan Lonowski Commented Oct 21, 2013 at 13:02
Add a ment  | 

1 Answer 1

Reset to default 7

If you were expecting hello world as text:

<p>
    hello world
</p>

Then, Jade needs just a bit more instruction since the default meaning of a line-break and indent is a child element.

Options include:

  • Keeping the element and text on the same line ("Inline in a Tag"):

    p #{user.name}
    

    Also, if that's the only text within the <p>:

    p= user.name
    
  • Using a | to specify the line as text ("Piped Text"):

    p
      | #{user.name}
    
  • Trailing the element with a . so all content under it is text ("Block in a Tag"):

    p.
      #{user.name}
    
发布评论

评论列表(0)

  1. 暂无评论