请考虑以下三个非常相似的页面。
{-# LANGUAGE OverloadedStrings, TypeFamilies, QuasiQuotes,
TemplateHaskell, MultiParamTypeClasses #-}
import Yesod
import Control.Applicative
import Data.Text (Text)
import Text.Hamlet
data Example = Example
mkYesod "Example" [parseRoutes|
/ RootR GET
/page PageR GET
/page2 Page2R GET
|]
instance Yesod Example
getRootR :: GHandler sub Example RepHtml
getRootR = do
defaultLayout [whamlet|
$doctype 5
<html>
<head>
<title>Tutorial, hello root
<body>
<h1 id="greeting">Hello root
|]
getPageR :: GHandler sub Example RepHtml
getPageR = defaultLayout $ do
toWidgetHead [hamlet| <meta charset="utf-8"> |]
setTitle "hello page"
toWidget [hamlet|
<h1 id="greetings2">Hello page
|]
getPage2R :: GHandler sub Example RepHtml
getPage2R = defaultLayout $ do
toWidget [hamlet|
$doctype 5
<html>
<head>
<title>Tutorial, hello page2
<body>
<h1 id="greeting">Hello page2
|]
main :: IO ()
main = warpDebug 3000 Example
RootR 和 page2 提供相同的输出(我的意思是标签和结构),而“页面”与两者略有不同。输出首先是“root”和“page2”:
<!DOCTYPE html>
<html><head><title></title></head><body><!DOCTYPE html>
<html><head><title>Tutorial, hello page2</title>
</head>
<body><h1 id="greeting">Hello page2</h1>
</body>
</html>
</body></html>
而“page”的输出是
<!DOCTYPE html>
<html><head><title>hello page</title><meta charset="utf-8"> </meta>
</head><body><h1 id="greetings2">Hello page</h1>
</body></html>
为什么“root”和“page2”中有额外的& -标签?我应该在代码中添加一些东西还是拿走一些东西?
谢谢你的帮助!