1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-24 05:17:03 +00:00

HandleDir: customize file/dir listing page through registered view engine

Former-commit-id: 98bfd9d5a073c5bc7c2c167e2a72dd7b05bfb24a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-07 06:11:44 +03:00
parent 87e08dbddc
commit cba6351d62
5 changed files with 150 additions and 140 deletions

View File

@@ -567,9 +567,13 @@ func DirectoryExists(dir string) bool {
}
// DirListRichOptions the options for the `DirListRich` helper function.
// The Tmpl's "dirlist" template will be executed.
type DirListRichOptions struct {
// If not nil then this template's "dirlist" is used to render the listing page.
Tmpl *template.Template
// If not empty then this view file is used to render the listing page.
// The view should be registered with `Application.RegisterView`.
// E.g. "dirlist.html"
TmplName string
}
// DirListRich is a `DirListFunc` which can be passed to `DirOptions.DirList` field
@@ -580,8 +584,7 @@ func DirListRich(opts ...DirListRichOptions) DirListFunc {
if len(opts) > 0 {
options = opts[0]
}
if options.Tmpl == nil {
if options.TmplName == "" && options.Tmpl == nil {
options.Tmpl = DirListRichTemplate
}
@@ -630,6 +633,10 @@ func DirListRich(opts ...DirListRichOptions) DirListFunc {
})
}
if options.TmplName != "" {
return ctx.View(options.TmplName, pageData)
}
return options.Tmpl.ExecuteTemplate(ctx, "dirlist", pageData)
}
}