implement new template func "urlToNotice"

This commit is contained in:
Andre Staltz 2021-02-25 17:18:51 +02:00
parent f774817536
commit 62d31f08b9
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 40 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
"github.com/gorilla/csrf"
@ -80,6 +82,31 @@ func New(
return r.RequestURI == url.Path
}
}),
render.InjectTemplateFunc("urlToNotice", func(r *http.Request) interface{} {
return func(name string) *url.URL {
noticeName := admindb.PinnedNoticeName(name)
if !noticeName.Valid() {
return nil
}
notice, err := ps.Get(r.Context(), noticeName, "en-GB")
if err != nil {
return nil
}
route := router.CompleteApp().GetRoute(router.CompleteNoticeShow)
if route == nil {
return nil
}
u, err := route.URLPath()
if err != nil {
return nil
}
noticeID := strconv.FormatInt(notice.ID, 10)
q := u.Query()
q.Add("id", noticeID)
u.RawQuery = q.Encode()
return u
}
}),
render.InjectTemplateFunc("is_logged_in", func(r *http.Request) interface{} {
no := func() *admindb.User { return nil }

View File

@ -72,6 +72,19 @@
</div>
</div>
{{end}}
{{block "footer" .}}
{{$cocUrl := urlToNotice "NoticeCodeOfConduct"}}
{{$ppUrl := urlToNotice "NoticePrivacyPolicy"}}
<footer>
{{if $cocUrl}}
<a href="{{$cocUrl}}">{{i18n "NoticeCodeOfConduct"}}</a>
{{end}}
{{if $ppUrl}}
<a href="{{$ppUrl}}">{{i18n "NoticePrivacyPolicy"}}</a>
{{end}}
</footer>
{{end}}
</div>
</body>
</html>