3 ms·
I do too, for simple things. But what do you do when you have repeating patterns and want to eliminate duplication? Usually a template language would be introdu
by ptx 6y ago
I do too, for simple things. But what do you do when you have repeating patterns and want to eliminate duplication? Usually a template language would be introduced, and now it's not HTML anymore; tools that work on plain HTML don't work with the special template language; commenting out code gets tricky because the same file has multiple kinds of syntax intermixed. And in addition to your HTML and your template language you still have your programming language.
Kotlin solves this by using the programming language for the whole thing, allowing you to extract repeating parts using plain functions as you would with any other code. Of course it's not as well suited as HTML itself for writing HTML, but it might be better than HTML + some template language + some programming language.
Another way to go, to avoid having a mysterious mixture of almost-HTML embedded within some other syntax, is to do what Thymeleaf does[1] and have the template language be embedded inside HTML (rather than the other way around) so that the template file is actually valid HTML.
[1] https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#support-for-html5-friendly-attribute-and-element-names https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.h...