mycorrhiza icon indicating copy to clipboard operation
mycorrhiza copied to clipboard

Template library

Open bouncepaw opened this issue 3 years ago β€’ 2 comments

We use the quicktemplate library for almost all of HTML templating tasks in the project.

Contra:

  • Yet another dependency (all dependencies fail and are not to be trusted)
  • Yet another non-standard thing
  • We have twice as many files (.qtpl and .qtpl.go)
  • People are irritated for some reason?

Pro:

  • The core idea of the library (templates are normal Go functions) makes sense
  • The syntax of the templating language is very expressive
  • The library is quite fast, they say

I do not think changing quicktemplate to any other non-stdlib templating solution is a good idea. But what about stdlib's html/template?

=> https://godocs.io/html/template

Contra:

  • The API is ridiculous. You have to parse each template (and that may fail) and then you have to β€˜execute’ it (and that may fail too). Simply unbearable
  • If we use html/template, it will be easier to implement template configuration, which is undesirable

Pro:

  • It is in stdlib
  • If we store the templates as separate .html files, every text editor will have a proper syntax highlighting. Compare with .qtpl which requires additional configuration everywhere

So, what is better? Cross your sword!

bouncepaw avatar Nov 05 '21 19:11 bouncepaw

After like six experiments, I'm starting to like this approach:

  • stdlib templates
  • l10n are done using {{block}} in place in English
  • they are then redefined for Russian for Russian versions of templates

Take a look at how categories views are done.

This approach also covers #138.

bouncepaw avatar Mar 26 '22 16:03 bouncepaw