“ .hamlet”文件中的^ {......是什么意思

时间:2019-12-02 01:11:33

标签: haskell yesod shakespeare-text

在此“ .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}

1 个答案:

答案 0 :(得分:3)

您链接的示例可能会有些混乱,因为您看不到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,以便对此有所了解。