github.com/louisevanderlith/droxolite@v1.20.2/drx/template.go (about)

     1  package drx
     2  
     3  import (
     4  	"html/template"
     5  	"log"
     6  	"os"
     7  	"path/filepath"
     8  	"strings"
     9  )
    10  
    11  //LoadTemplate parses html files, to be used as layouts
    12  func LoadTemplate(viewPath string) (*template.Template, error) {
    13  	return template.ParseFiles(FindFiles(viewPath)...)
    14  }
    15  
    16  func FindFiles(templatesPath string) []string {
    17  	var result []string
    18  
    19  	filepath.Walk(templatesPath, func(path string, f os.FileInfo, err error) error {
    20  		if err != nil {
    21  			log.Println(err)
    22  		}
    23  
    24  		if !f.IsDir() && strings.HasSuffix(path, ".html") {
    25  			result = append(result, path)
    26  		}
    27  
    28  		return nil
    29  	})
    30  
    31  	return result
    32  }