implement new template func "urlToNotice"
This commit is contained in:
parent
f774817536
commit
62d31f08b9
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue