我构建了这样的基本yesod模板:
stack new kek yesod-simple
stack build
没关系。之后,我尝试在this教程echo
部分:
我将/echo/#String EchoR GET
添加到配置/路由
我还在Home.hs中添加了以下处理程序
getEchoR :: String -> Handler RepHtml
getEchoR theText = do
defaultLayout $ do
[whamlet|<h1>#{theText}|]
当我再次尝试stack build
时,我收到以下错误:
[8 of 9] Compiling Handler.Home ( src/Handler/Home.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0/build/Handler/Home.o )
/home/kek/me/haskell/webservices/lol/src/Handler/Home.hs:72:23: error: parse error on input ‘{’
-- While building package lol-0.0.0 using:
/home/kek/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0 build lib:lol --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
我刚从教程中复制了这个whamlet[...]
字符串,其他一切都是根据yesod-simple模板生成的,我没有改变任何东西。
upd:我设法通过将处理程序代码更改为以下内容来实现它:
getEchoR :: String -> Handler RepHtml
getEchoR theText = do
defaultLayout $ do
setTitle "My Awesome Site"
$(widgetFile "echo")
将样本echo.hamlet
文件添加到/ templates /
<!-- Static navbar -->
<nav .navbar.navbar-default.navbar-static-top>
<div .container>
<div .navbar-header>
<button type="button" .navbar-toggle.collapsed data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<div #navbar .collapse.navbar-collapse>
<ul .nav.navbar-nav>
<ul .nav.navbar-nav.navbar-right>
<!-- Page Contents -->
<div .container>
<!-- Footer -->
<footer .footer>
<div .container>
<p .text-muted>
所以我的问题改为:在这种情况下,我是否有义务这样做?
答案 0 :(得分:3)
{-# LANGUAGE QuasiQuotes #-}
是quasiquote语法;这需要启用QuasiQuotes GHC扩展。
启用它的最简单方法是将pragma {{1}}添加到.hs文件的顶部(仅为该文件启用它) - 您还可以在项目范围内启用编译指示Cabal文件)。