1

I am working on a golang project using gin and go templating. My templates are in a structure like so:

C:.
├───components
├───display
....

I would like to add subdirectories to organise the templates, like so:

C:.
├───components
│   └───tables
├───display
...

I use gin's HTMLglob to load the templates like so:

r.LoadHTMLGlob("./templates/*/*")

or alternatively

r.LoadHTMLGlob("./templates/**/*")

(the second version was recommended in a couple of templating examples, so I tried it)

The template names are all different so there is no issue of name duplication. I'm just trying to store them in a directory/subdirectory structure that makes them easier to locate.

However, when I introduce the tables subdirectory, the compiler gives me the following error:

panic: read templates\components\tables: Incorrect function.

I'm relatively unfamiliar with the globstar pattern matching which I believe is used by HTMLglob, but I don't quite see why recursing into a sub-sub-directory should cause an error.

It doesn't make any difference whether tables contains a template file or not.

I'd welcome any solution that lets me organise my templates in subdirectories

0

Browse other questions tagged or ask your own question.