-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
Hi, I'm working on a small Go project and would like to organize my HTML files properly. For example, if there's a dashboard screen with a form and a table, I'll put the form and table in separate partial files within the same folder, prefixed with _.
views/
├─ dashboard/
├── index.html
├── _table.html
├── _form.html
And here's the way configured it
config := goview.Config{
...
Partials: getPartialList(),
...
}
goview.New(config)
// .....
func getPartialList() []string {
partials := []string{}
err := filepath.Walk(ROOT_VIEW_PATH, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
fileName := info.Name()
fileExtension := filepath.Ext(fileName)
if fileExtension == ".html" && strings.HasPrefix(fileName, "_") {
filePath := strings.Split(path, ROOT_VIEW_PATH)[1]
filePathWithoutExt := filePath[:len(filePath)-len(fileExtension)]
partials = append(partials, filePathWithoutExt)
}
}
return nil
})
if err != nil {
log.Info("Fail to get partial files", err.Error())
}
return partials
}I saw one of the open issue also mention a need for a way to configure a partial folder and I think maybe registering any HTML file prefixed with _ within the view folder might be a good idea.
So I just want to propose this idea so you don't need to manually add your folder list or write a function to get all of your partial paths to be able to use them as partials.
hoangmirs
Metadata
Metadata
Assignees
Labels
No labels