diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-04-17 23:58:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 15:58:37 +0000 |
commit | 3feba9f1f44156c256a30d25ad1c25f751819c94 (patch) | |
tree | 77d9575edc49e625b54f5358d67dba0764b1a553 /modules/templates | |
parent | bafb80f80d5505b03e5994d1ea6e2dab10052fe1 (diff) | |
download | gitea-3feba9f1f44156c256a30d25ad1c25f751819c94.tar.gz gitea-3feba9f1f44156c256a30d25ad1c25f751819c94.zip |
Allow everyone to read or write a wiki by a repo unit setting (#30495)
Replace #6312
Help #5833
Wiki solution for #639
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 5d2fa79bc5..360b48c594 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -34,6 +34,7 @@ func NewFuncMap() template.FuncMap { // ----------------------------------------------------------------- // html/template related functions "dict": dict, // it's lowercase because this name has been widely used. Our other functions should have uppercase names. + "Iif": Iif, "Eval": Eval, "SafeHTML": SafeHTML, "HTMLFormat": HTMLFormat, @@ -238,6 +239,17 @@ func DotEscape(raw string) string { return strings.ReplaceAll(raw, ".", "\u200d.\u200d") } +// Iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version, +// and it could be simply used as "{{Iif expr trueVal}}" (omit the falseVal). +func Iif(condition bool, vals ...any) any { + if condition { + return vals[0] + } else if len(vals) > 1 { + return vals[1] + } + return nil +} + // Eval the expression and return the result, see the comment of eval.Expr for details. // To use this helper function in templates, pass each token as a separate parameter. // |