在这段".hamlet“代码中,我想知道^{copyright}行是什么意思
$doctype 5
<html>
<head>
<title>#{pageTitle} - My Site
<link rel=stylesheet href=@{Stylesheet}>
<body>
<h1 .page-title>#{pageTitle}
<p>Here is a list of your friends:
$if null friends
<p>Sorry, I lied, you don't have any friends.
$else
<ul>
$forall Friend name age <- friends
<li>#{name} (#{age} years old)
<footer>^{copyright}发布于 2019-12-02 13:58:22
您所链接的示例可能会有一点混乱,因为您在任何地方都看不到copyright函数。copyright只是另一个函数。您可以使用^{..}函数在其中嵌入另一个小部件。此示例可能会对您有所帮助:
#!/usr/bin/env stack
-- stack --resolver lts-13.19 script
{-# LANGUAGE QuasiQuotes #-}
import Text.Blaze.Html
import Text.Blaze.Html.Renderer.Text (renderHtml)
import Text.Hamlet
hello :: Html
hello = [shamlet|
<body>
<p>Hello world
^{copyRight}
|]
copyRight :: Html
copyRight = [shamlet|
<p>Copyright by the SPJ
|]
main :: IO ()
main = do
let txt = renderHtml hello
print txt并且在执行它时:
$ stack hamlet.hs
"<body><p>Hello world</p>\n<p>Copyright by the SPJ</p>\n</body>\n"我建议您通过widgets chapter来更好地理解这一点。
https://stackoverflow.com/questions/59131483
复制相似问题