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 ...

1
  • Depends on what you were expecting the output to be. What would you consider "correct" in this case? Commented Oct 21, 2013 at 13:02

1 Answer 1

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}
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.