Bug 38720 - HTML1 no longer valid? TT tags can be present in HTML without breaking the translator tool
Summary: HTML1 no longer valid? TT tags can be present in HTML without breaking the tr...
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Templates (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 38714
  Show dependency treegraph
 
Reported: 2024-12-17 08:47 UTC by Jonathan Druart
Modified: 2025-01-23 15:14 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 38720: HTML1 no longer valid - remove xt/tt_valid.t (4.17 KB, patch)
2025-01-23 15:13 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2024-12-17 08:47:08 UTC
We have the following coding guidelines:

```
HTML1: Template Toolkit markup inside HTML

Avoid [% IF %] inside tags because the translation tools try to read the templates as straight HTML and most TT comments inside tags probably confuse/break them. The most common example of an incorrect construction:

<option value="1" [% IF (selected) %] selected="selected" [% END %]>Yes</option>

This must be written this way:

[% IF (selected) %]
 <option value="1" selected="selected">Yes</option>
[% ELSE %]
 <option value="1">Yes</option>
[% END %]
```

Everybody (should) know about it, and we are all aware it must not be done like that.
But... I will need it for bug 38664 and I have decided to have a look at fixing it.

However I have not managed to break anything!

I did introduce TT tags within HTML tags, but the strings are correctly picked and the translated templates is perfectly generated.

What am I missing here? Did we finally fix this long-standing problem without knowing it?
Comment 1 Victor Grousset/tuxayo 2024-12-20 21:28:50 UTC
> What am I missing here? Did we finally fix this long-standing problem without knowing it?

Either that or it was only valid with HTML::Template
Because that's how old that guideline is:
https://web.archive.org/web/20060902045435/Http://www.kohadocs.org/codingguidelines.html
https://wiki.koha-community.org/w/index.php?title=Coding_Guidelines&oldid=473

It was updated for the switch to TT
https://wiki.koha-community.org/w/index.php?title=Coding_Guidelines&type=revision&diff=6700&oldid=6210

So maybe it was still a valid issue that got fixed years later with a fix for something else in the translation script. Or it wasn't actually valid anymore but it was assumed to be.


----


Anyway, I guess you can use it safely for bug 38664 if you see that it doesn't create broken strings. If after your work there and your failed attempts to break things here, HTML1 could safely be obsoleted if nothing comes up.
Comment 2 Jonathan Druart 2025-01-15 13:24:53 UTC
Found one problem so far:

<li [% IF loop.count > 5 && !facet.active %]class="collapsible-facet" style="display:none"[% END %]>

It breaks because of the '>' in the TT condition.
Comment 3 Jonathan Druart 2025-01-23 15:13:13 UTC
Created attachment 177062 [details] [review]
Bug 38720: HTML1 no longer valid - remove xt/tt_valid.t
Comment 4 Jonathan Druart 2025-01-23 15:14:17 UTC
(In reply to Jonathan Druart from comment #2)
> Found one problem so far:
> 
> <li [% IF loop.count > 5 && !facet.active %]class="collapsible-facet"
> style="display:none"[% END %]>
> 
> It breaks because of the '>' in the TT condition.

We might need to reintroduce the test with an adjustment to catch that, but it's for later.
Comment 5 Jonathan Druart 2025-01-23 15:14:45 UTC
Test plan:
Test bug 38714, if there is nothing wrong found there, this can go.