title: How can use both LoadHTMLGlob and LoadHTMLFiles
body: <p>I want separator logical template from difference subdirectories under <code>templates</code> folder, the following is my templates folder</p>
  <pre><code>templates
  ├── authentication
  │   ├── login.gohtml
  │   └── logout.gohtml
  ├── index.gohtml
  └── profile
      └── userinfo.gohtml
  </code></pre>
  <p>Here is <code>main.go</code></p>
  <pre class="lang-golang prettyprint-override"><code>
  package main
  
  import (
      &quot;github.com/gin-gonic/gin&quot;
  )
  
  func main() {
      router := gin.New()
  
      // router.Use(Threshold())   // not finished yet
      router.Use(Cors())
  
      // load templates
      // router.LoadHTMLGlob(&quot;templates/authentication/*.gohtml&quot;)
      router.LoadHTMLGlob(&quot;./templates/*/*.gohtml&quot;)
      router.LoadHTMLGlob(&quot;./templates/*.gohtml&quot;)
      // set static folder
      router.Static(&quot;/static&quot;, &quot;./public&quot;)
  
      // handler the favicon.ico
      router.StaticFile(&quot;/favicon.ico&quot;, &quot;./public/images/favicon.ico&quot;)
  
  
      InjectRoutes(router)
  
  
  
      // run the server at default port 8080
      router.Run(&quot;:8080&quot;)
  }
  
  </code></pre>
  <p>InjectRoutes come from <code>route.go</code></p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;github.com/gin-gonic/gin&quot;
  
      auth &quot;github.com/yangwawa0323/mywebapp/v2/authentication&quot;
      &quot;github.com/yangwawa0323/mywebapp/v2/profile&quot;
  )
  
  // Route struct
  type Route struct {
      path         string
      handler      gin.HandlerFunc
      method       string
      templateFile interface{}
  }
  
  // R is alias of `Route`
  type R = Route
  
  // GenerateRoutes generate all the routes.
  func GenerateRoutes() []Route {
      return []Route{
          R{&quot;/&quot;, HomePage, &quot;GET&quot;, &quot;./templates/index.gohtml&quot;},
          R{&quot;/login&quot;, auth.Login, &quot;GET&quot;, nil},
          R{&quot;/logout&quot;, auth.Logout, &quot;GET&quot;, nil},
  
          R{&quot;/profile/:user/&quot;, profile.UserInfo, &quot;GET&quot;, nil},
      }
  }
  
  // InjectRoutes function inject routes to gin.Engine
  func InjectRoutes(router *gin.Engine) {
      for _, r := range GenerateRoutes() {
          if r.templateFile != nil {
              router.LoadHTMLFiles(r.templateFile.(string))
          }
          switch r.method {
          case &quot;POST&quot;:
              router.POST(r.path, r.handler)
          case &quot;DELETE&quot;:
              router.DELETE(r.path, r.handler)
          case &quot;PUT&quot;:
              router.PUT(r.path, r.handler)
          default:
              router.GET(r.path, r.handler)
          }
      }
  }
  
  
  </code></pre>
  <p>Here is debug message</p>
  <pre><code>[GIN-debug] [WARNING] Running in &quot;debug&quot; mode. Switch to &quot;release&quot; mode in production.
   - using env:   export GIN_MODE=release
   - using code:  gin.SetMode(gin.ReleaseMode)
  
  [GIN-debug] Loaded HTML Templates (4): 
      - 
      - login.gohtml
      - logout.gohtml
      - userinfo.gohtml
  
  [GIN-debug] Loaded HTML Templates (2): 
      - index.gohtml
      - 
  
  2021/01/03 10:02:34 http: panic serving [::1]:50590: html/template: &quot;userinfo.gohtml&quot; is undefined
  goroutine 34 [running]:
  net/http.(*conn).serve.func1(0xc000302000)
      /usr/lib/go-1.13/src/net/http/
  </code></pre>
  <p>As you can see that there are loaded the templates , but LoadHTMLGlod and LoadHTMLFiles only one is working, the lastest has precedence which overrided the previous one.</p>
  <p>My question is how to wrote the glob to implement my requirement or has the other skill to wrote the code , I don't want make a new directory and put the <code>index.gohtml</code> in it, even it's working ? Thanks.</p>