Skip to content

Commit a58bd76

Browse files
Merge pull request #10 from kohkimakimoto/dev
Implement ErrSkipAssignment for shared context providers
2 parents 84f92b0 + 5b729c1 commit a58bd76

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

renderer.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ package viewkit
22

33
import (
44
"bytes"
5-
"io"
6-
"strings"
7-
5+
"errors"
86
"github.com/kohkimakimoto/echo-viewkit/pongo2"
97
"github.com/labstack/echo/v4"
8+
"io"
9+
"strings"
1010
)
1111

12+
// ErrSkipAssignment is returned by SharedContextProviderFunc to indicate
13+
// that the key-value assignment should be skipped and no value should be assigned
14+
// to the template context.
15+
var ErrSkipAssignment = errors.New("skip assignment")
16+
1217
// Renderer is a renderer implementation for Echo.
1318
// see https://echo.labstack.com/docs/templates
1419
type Renderer struct {
@@ -36,6 +41,9 @@ func (r *Renderer) Render(w io.Writer, name string, data any, c echo.Context) er
3641
for k, provider := range r.providers {
3742
v, err := provider(c)
3843
if err != nil {
44+
if errors.Is(err, ErrSkipAssignment) {
45+
continue
46+
}
3947
return err
4048
}
4149
pongo2Context[k] = v

0 commit comments

Comments
 (0)