Wrapping HTML in templates

Gervase Markham gerv at mozilla.org
Sun Sep 12 16:24:01 UTC 2004


Christian Robottom Reis wrote:
> So here's a public cry for help that others may enjoy as well:

Here's my view :-) Looking at Jouni's, we seem to have a lot in common.

>     a) How does one wrap a long link which isn't broken by template
>        statements?
> 
>         <p><a href=query.cgi>Skip all this nonsense, and go back to the query page</a>\n";

Easy - in the middle of the text.

>     b) How does one wrap a long link which *is* broken by template
>        statements?
> 
>        <a href="[% INCLUDE diffurl attachid=attachid %]&headers=[% headers FILTER html %]&context=file">File</a> / 

Current practice seems to be to wrap at the beginning of a statement. So:

<a href="[% INCLUDE diffurl attachid=attachid %]&headers=
          [% headers FILTER html %]&context=file">File</a> /

>     c) How does one wrap a long HTML statement that includes <a> tags
>        (and therefore doesn't like spurious spacing here and there) such
>        as:
> 
>        <table class="file_table"><thead><tr><td class="file_head" colspan="2"><a href="#" onclick="return twisty_click(this)">[% collapsed ? '(+)' : '(-)' %]</a><input type="checkbox" name="[% file.filename FILTER html %]"[% collapsed ? '' : ' checked' %] style="display: none"> 

One doesn't wrap such a thing. One does what you suggest:

>        <table class="file_table">
>          <thead>
>            <tr>
>              <td class="file_head" colspan="2"><a href="#" onclick="return twisty_click(this)">[% collapsed ? '(+)' : '(-)' %]</a><input type="checkbox" name="[% file.filename FILTER html %]"[% collapsed ? '' : ' checked' %] style="display: none"> 
>              [...]
>              </td>
>            </td>
>          </thead>
>         </table>

... and then wraps the middle as follows:
                <td class="file_head" colspan="2">
                  <a href="#" onclick="return twisty_click(this)">
                  [% collapsed ? '(+)' : '(-)' %]</a>

                  <input type="checkbox"
                         name="[% file.filename FILTER html %]"
                         [% collapsed ? '' : ' checked' %]
                         style="display: none">

> I've tended to use the policy: if a large portion of the line isn't
> wrappable, don't bother with wrapping smaller parts of it unless it
> makes things a lot better. Is that a bad policy?

Yes. :-) Tags should always be nested if possible (as in your second 
example). Then, do your best with what's left.

> Note that one alternative is wrapping *inside* tags and TT statements.

Evil for TT statements. OK for tags, if you break it up at attribute 
boundaries and align attributes, like I did above.

Gerv



More information about the developers mailing list