Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add page-specific class per template #3814

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/api/util/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ func templatePage(
obj map[string]any,
) {
const pageTmpl = "page.tmpl"

// Render given template inside the page.
obj["pageContent"] = template

// Inject specific page class by trimming
// ".tmpl" suffix. In the page template
// (see page.tmpl) this will be appended
// with "-page", so "index.tmpl" for example
// ends up with class "page index-page".
obj["pageClass"] = template[:len(template)-5]

c.HTML(code, pageTmpl, obj)
}
4 changes: 2 additions & 2 deletions internal/web/confirmemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (m *Module) confirmEmailGETHandler(c *gin.Context) {
// Serve page where user can click button
// to POST confirmation to same endpoint.
page := apiutil.WebPage{
Template: "confirm_email.tmpl",
Template: "confirm-email.tmpl",
Instance: instance,
Extra: map[string]any{
"email": email,
Expand Down Expand Up @@ -127,7 +127,7 @@ func (m *Module) confirmEmailPOSTHandler(c *gin.Context) {
// Serve page informing user that their
// email address is now confirmed.
page := apiutil.WebPage{
Template: "confirmed_email.tmpl",
Template: "confirmed-email.tmpl",
Instance: instance,
Extra: map[string]any{
"email": user.Email,
Expand Down
2 changes: 1 addition & 1 deletion internal/web/login-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m *Module) loginGETHandler(c *gin.Context) {
}

page := apiutil.WebPage{
Template: "login_info.tmpl",
Template: "login-info.tmpl",
Instance: instance,
OGMeta: apiutil.OGBase(instance),
Stylesheets: []string{cssAbout, cssLoginInfo},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions web/template/page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ image/webp
{{- end }}
<title>{{- template "instanceTitle" . -}}</title>
</head>
<body>
<body class="page{{- if .pageClass }} {{ .pageClass }}-page{{- end -}}">
{{- include "login_button.tmpl" . | indent 3 }}
<div class="page">
<header class="page-header">
{{- include "page_header.tmpl" . | indent 3 }}
</header>
Expand All @@ -83,6 +82,5 @@ image/webp
<footer class="page-footer">
{{- include "page_footer.tmpl" . | indent 3 }}
</footer>
</div>
</body>
</html>