pugpugjs

Multiline non-compiled attribute in jade



I tried to do so:

body(
  |{% case page.url %}
  | {% when '/' %}
  |    class="hellopage"
  | {% when page.url contains '/gallery/' %}
  |    class="gallerypage"
  |{% endcase %}
  )

This {% .. %} stuff for Liquid actually.
So, it is not compiled. How can I write a multi-line attribute in tag?


Solution

  • EDIT:

    The problem is that the Pug compiler does not like the {% character sequences in the attribute. In your specific scenario, this the work-around would be to escape the newlines and put Liquid logic in the attribute value string, as well:

    body(class="\
       {% case page.url %}\
        {% when '/' %}\
           hellopage\
        {% when page.url contains '/gallery/' %}\
           gallerypage\
       {% endcase %}"
      )
    

    Old answer:

    I don't think that you need the pipe character (|) to do this. Attributes on multiple lines are supported by Pug. Something like this should be sufficient:

    body(
       {% case page.url %}
        {% when '/' %}
           class="hellopage"
        {% when page.url contains '/gallery/' %}
           class="gallerypage"
       {% endcase %}
      )
    

    Should work, but haven't tested it though (due to a lack of a Liquid+Pug testing environment).