1
매우 유사한 다음 세 페이지를 고려하십시오.yesodweb -example 및 출력의 여분 태그
{-# 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 및 페이지 2가 동일한 출력을주는 두개의 약간의 차이가 "페이지"동안 (I 태그를 & 구조를 의미한다). & "루트"에서 추가 & -tags가 왜 "페이지"의 출력이
<!DOCTYPE html>
<html><head><title>hello page</title><meta charset="utf-8"> </meta>
</head><body><h1 id="greetings2">Hello page</h1>
</body></html>
동안 "
<!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>
: 출력 먼저"루트 "&"페이지 2 "이다 2 쪽"? 코드에 뭔가를 추가해야합니까?
도움 주셔서 감사합니다.
고마워요! 나는 그 책에서 예제를 취했고 예제에서는 다른 함수 (widgetToPageContent)를 사용했다는 것을 바로 알지 못했다. 다른 사람들이 배울 때 자신의 "사례"를 공유하고 싶다면 "예고편"과 함께 예디 - 위키에 추가 할 것입니다. – Gspia
그리고 hamletToRepHtml이 있어야하고 widgetToPageContent가 없어야합니다. – Gspia