line breaks in Jade conditionals

I am trying to figure out if there is a way to insert line breaks in a Jade template conditional. For example, consider the following lengthy conditional:

if superlongstatementnumberone == true && superlongstatementnumbertwo == false && superlongstatementnumberthree == true
  div: span some content

would be much more manageable as:

if superlongstatementnumberone == true 
  && superlongstatementnumbertwo == false 
  && superlongstatementnumberthree == true
  div: span some content

it is possible to do this with non-conditional parts but the above does not work with code statements according to my experimentation. It sort of inconceivable to me that a language could reach the penetration of Jade without any support for this.

I hope this post will prove me right...


You can use Code with a leading - minus (word seperator) like described in the offical Jade - Language Reference

Newer Jade/Pug versions supports code blocks of buffered and unbuffered code with a sinlg minus with the indentation of following lines, like this example:

- 
  if (superlongstatementnumberone == true 
    && superlongstatementnumbertwo == false 
    && superlongstatementnumberthree == true) {
      var someContent = 'some content'
  }
div: span= someContent

In older Jade/Pug versions you need to add the leading - minus to all lines, like in this example:

- if (superlongstatementnumberone == true 
-   && superlongstatementnumbertwo == false 
-   && superlongstatementnumberthree == true) {
-      var someContent = 'some content'
- }
div: span= someContent

Take a look on a working CodePen.

链接地址: http://www.djcxy.com/p/88902.html

上一篇:

下一篇: Jade条件中的换行符