(err ErrViewNotExist)
| 3847 | const fallbackViewOnce = "iris.fallback.view.once" |
| 3848 | |
| 3849 | func (ctx *Context) fireFallbackViewOnce(err ErrViewNotExist) error { |
| 3850 | // Note(@kataras): this is our way to keep the same View method for |
| 3851 | // both fallback and normal views, remember, we export the whole |
| 3852 | // Context functionality to the end-developer through the fallback view provider. |
| 3853 | if ctx.values.Get(fallbackViewOnce) != nil { |
| 3854 | return err |
| 3855 | } |
| 3856 | |
| 3857 | v := ctx.values.Get(ctx.app.ConfigurationReadOnly().GetFallbackViewContextKey()) |
| 3858 | if v == nil { |
| 3859 | return err |
| 3860 | } |
| 3861 | |
| 3862 | providers, ok := v.([]FallbackViewProvider) |
| 3863 | if !ok { |
| 3864 | return err |
| 3865 | } |
| 3866 | |
| 3867 | ctx.values.Set(fallbackViewOnce, struct{}{}) |
| 3868 | |
| 3869 | var pErr error |
| 3870 | for _, provider := range providers { |
| 3871 | pErr = provider.FallbackView(ctx, err) |
| 3872 | if pErr != nil { |
| 3873 | if vErr, ok := pErr.(ErrViewNotExist); ok { |
| 3874 | // This fallback view does not exist or it's not responsible to handle, |
| 3875 | // try the next. |
| 3876 | pErr = vErr |
| 3877 | continue |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | // If OK then we found the correct fallback. |
| 3882 | // If the error was a parse error and not a template not found |
| 3883 | // then exit and report the pErr error. |
| 3884 | break |
| 3885 | } |
| 3886 | |
| 3887 | return pErr |
| 3888 | } |
| 3889 | |
| 3890 | // FallbackView registers one or more fallback views for a template or a template layout. |
| 3891 | // When View cannot find the given filename to execute then this "provider" |
no test coverage detected