Whitespace control and indentation

9 views
Skip to first unread message

Vincent Panel

unread,
Jul 2, 2019, 5:52:12 AM7/2/19
to pocoo-libs
Hello,

I'm struggling with indentation and whitespace control. I find it quite counter-intuitive. Isn't there any way to just remove newlines left after a block evaluation, without removing indentation ? For instance, let's take the following example, where you have indented text and you just want to have them without any blank line in between. Isn't there any better way than the following example ?

  Indented0
{%- if True %}
  Indented1
{% else %}
  Indented2
{% endif -%}
{##}  Indented3
  Indented4
  Indented5

Thanks,

Jonathan Mayer

unread,
Jul 4, 2019, 2:11:58 PM7/4/19
to pocoo...@googlegroups.com
What works for me: I always consistently use "{%-" (the "remove all whitespace to the left" tag variant) for every command and comment.  Every command starts on a new line.  I only use the right-gobble in rare exceptional circumstances.

By sticking with this style I get consistent and predictable results.

If I need a new line, I'll do this:

Lorem ipsum.
{# blank line #}
{%- if condition %}
  This could be indented.
{%- else %}{# condition #}
  This might be indented.
{%- endif %}{# condition #}
    Foo is indented.

Note that you need the minus on all commands, including the else clause, for consistent results.

Left gobble is preferred over right gobble because indentation is common, but trailing whitespace is rare.


--
You received this message because you are subscribed to the Google Groups "pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pocoo-libs+...@googlegroups.com.
To post to this group, send email to pocoo...@googlegroups.com.
Visit this group at https://groups.google.com/group/pocoo-libs.
To view this discussion on the web visit https://groups.google.com/d/msgid/pocoo-libs/0653f2a4-9a80-478d-8b68-a54e9b408ccf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vincent Panel

unread,
Jul 4, 2019, 8:45:46 PM7/4/19
to pocoo...@googlegroups.com
Ok, many thanks. I more or less figured this out but you write it in a more straight forward way than I do.

Reply all
Reply to author
Forward
0 new messages