Hello and Happy New Year everyone
I am really excited to have the chance to propose a feature—a special case of which I have seen discussed here and there on the Internet, and even on this forum. It is possible to find Hugo users asking to allow layouts to have the *.gohtml
extension, mainly due to formatting issues. In fact, my initial motivation was exactly the same, but I think this potential feature can be generalised in a quite useful way.
What I propose is to define template extension aliases. In a nutshell, this allows creating several potential layout paths for one LayoutDescriptor
. Going back to the *.gohtml
example, whenever we want to generate paths for the “html” suffix, apart from constructing paths ending with .html
, we can also create those that end with .gohtml
. Depending on which one is specified first, this method also defines the priority (i.e., whether to take *.html
or *.gohtml
first) at little to no extra cost. I created a branch on a Hugo fork to illustrate this particular example.
Exploring this idea further, it can give users a comfortable amount of control over the lookup order (but not too much control, still letting Hugo do its magic). These extension aliases can, of course, be configurable so that users can define and organize them in order of priority. For instance, we can have HTML templates with the *.ahtml
extension take priority over *.bhtml
, *.bhtml
take priority over *.chtml
, and so on.
Additionally, this allows users to keep their formatting, syntax highlighting, and other logic separate for each extension alias. Although it is a very long shot, this could potentially be a step towards modular template engines in Hugo, allowing users to choose their favorite template syntax and thus promoting increased adoption and community growth.
In summary, defining template extension aliases can be beneficial for both individual developers and the broader community. This feature aligns well with Hugo’s commitment to performance and adaptability, ensuring that it continues to meet the evolving needs of its users.
I want to thank you for your attention and say that I would be delighted to move this idea further and create a GitHub proposal if there is a suitable amount of interest.
Happy coding!