View renders a template based on the registered view engine(s). First argument accepts the filename, relative to the view engine's Directory and Extension, i.e: if directory is "./templates" and want to render the "./templates/users/index.html" then you pass the "users/index.html" as the filename ar
(filename string, optionalViewModel ...interface{})
| 3937 | // |
| 3938 | // Examples: https://github.com/kataras/iris/tree/main/_examples/view |
| 3939 | func (ctx *Context) View(filename string, optionalViewModel ...interface{}) error { |
| 3940 | ctx.ContentType(ContentHTMLHeaderValue) |
| 3941 | |
| 3942 | err := ctx.renderView(filename, optionalViewModel...) |
| 3943 | if err != nil { |
| 3944 | if errNotExists, ok := err.(ErrViewNotExist); ok { |
| 3945 | err = ctx.fireFallbackViewOnce(errNotExists) |
| 3946 | } |
| 3947 | } |
| 3948 | |
| 3949 | if err != nil { |
| 3950 | if ctx.IsDebug() { |
| 3951 | // send the error back to the client, when debug mode. |
| 3952 | ctx.StopWithError(http.StatusInternalServerError, err) |
| 3953 | } else { |
| 3954 | ctx.SetErrPrivate(err) |
| 3955 | ctx.StopWithStatus(http.StatusInternalServerError) |
| 3956 | } |
| 3957 | } |
| 3958 | |
| 3959 | return err |
| 3960 | } |
| 3961 | |
| 3962 | func (ctx *Context) renderView(filename string, optionalViewModel ...interface{}) error { |
| 3963 | cfg := ctx.app.ConfigurationReadOnly() |
nothing calls this directly
no test coverage detected