Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] How many spaces of indentation in templates?

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: IKEDA Soji <address@concealed>
  • To: David Verdin <address@concealed>
  • Cc: address@concealed
  • Subject: Re: [sympa-developpers] How many spaces of indentation in templates?
  • Date: Fri, 11 Jan 2019 19:31:31 +0900

Hi David,

I use ~ modifier inside of tt2 blocks in web templates (not email template), like

[% FOREACH dude IN dudes ~%]
  [% IF dude.users ~%]
    [% FOREACH user IN dude.users ~%]
      [% IF user.email ~%]
        <li>[% user.email %]</li>
      [% ELSIF user.gecos ~%]
         <li>[% user.gecos %]</li>
      [% ELSE ~%]
        <li>[% ‘user’ | loc %]</li>
      [% END %]
    [%~ END %]
  [%~ END %]
[%~ END %]

This way, most of unnecessary spaces and blank lines are stripped (in above, only newlines after <li> element are left).

2019/01/11 19:04、David Verdin <address@concealed>のメール:

Hi Luc,

I prefer 4 spaces too.

Related question:

I, like Soji, tend to have exceptions for HTML. Namely, I try to distinguish TT2 tags indentation and the resulting HTML indentation.

I make a large usage of ending dashes (like in [% FOREACH -%]) in TT2 tags to allow to isolate these tags on single lines to prevent making their indentation to impact HTML.

Example:

<ol>

[% FOREACH dude IN dudes -%]

    [% IF dude.emails -%]

        [% FOREACH email IN dude.emails -%]

            [% IF email.canonical -%]

    <li>[% email.value %]</li>

            [% ENDIF -%]

        [% ENDFOR -%]

    [% ENDIF -%]

[% ENDFOR -%]

</ol>

Which would give :

<ol>

    <li>address@concealed</li>

    <li>address@concealed</li>

    <li>address@concealed</li>

</ol>

Whereas without the ending dashes, it would give:

<ol>





    <li>address@concealed</li>






 



    <li>address@concealed</li>

 

 

 






    <li>address@concealed</li>





</ol>

Regards,

David


On 11/01/2019 09:49, IKEDA Soji wrote:
address@concealed">
Hi,

I’m using 2 spaces for both tt2 elements and HTML elements (and there are some exception rules when HTML is enclosed by tt2, ...a bit hard to describe).

If another method was agreed, I won’t stick to my method.

2019/01/11 17:21、Luc Didry <address@concealed>のメール:

Hello,

I plan to correct indentation in the default tt2 template files to
make them more readable. How many spaces should I use? I saw templates
with 2 spaces and 4 spaces.

My personal preference is 4 spaces, like in the perl files.
-- 
Luc
"La route est longue, mais la voie est libre…" https://framasoft.org

Framasoft ne vit que par vos dons (déductibles des impôts). Merci d'avance pour votre soutien https://soutenir.framasoft.org





    
-- 
"Mieux vaut viser la perfection et la rater que viser la médiocrité et l'atteindre."
- Francis Blanche



Archive powered by MHonArc 2.6.19+.

Top of Page