问题描述
在完成网站第一个项目后,我想添加一些静态页面,我检查了以下 IHP - Recipes 静态页面。这就是我的处理方式:
data StaticController
= WelcomeAction
| AboutAction
deriving (Eq,Show,Data)
在Web/Static/About.hs
:
module Web.View.Static.About where
import Web.View.Prelude
data About = About
instance View About where
html About = [hsx| ~some html here~ |]
在Web/Controller/Static.hs
module Web.Controller.Static where
import Web.Controller.Prelude
import Web.View.Static.Welcome
import Web.View.Static.About
instance Controller StaticController where
action WelcomeAction = render WelcomeView
action AboutAction = render AboutView
`
我得到的错误是:
Web/Controller/Static.hs:8:35
Data constructor not in scope: AboutView
|
| action AboutAction = render AboutView
|
build/Generated/Types.hs:3:1
Unrecognised pragma
|
| {-# GHC_OPTIONS -Wno-unused-imports,-Wno-dodgy-imports,-Wno-unused-matches #-}module Generated.Types where
| ^^^
解决方法
您在名为 About
的数据类型中定义了视图。所以要渲染它,你应该调用 render About
,而不是 render AboutView
。
我建议将 About
重命名为 AboutView
,这更符合 IHP 约定:)