MCPcopy Create free account
hub / github.com/kataras/iris / View

Method View

context/context.go:3939–3960  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

3937//
3938// Examples: https://github.com/kataras/iris/tree/main/_examples/view
3939func (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
3962func (ctx *Context) renderView(filename string, optionalViewModel ...interface{}) error {
3963 cfg := ctx.app.ConfigurationReadOnly()

Callers

nothing calls this directly

Calls 7

ContentTypeMethod · 0.95
renderViewMethod · 0.95
fireFallbackViewOnceMethod · 0.95
IsDebugMethod · 0.95
StopWithErrorMethod · 0.95
SetErrPrivateMethod · 0.95
StopWithStatusMethod · 0.95

Tested by

no test coverage detected