0

在这个“.hamlet”代码中,我想知道^{copyright}line的含义是什么

$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}
4

1 回答 1

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"

我建议您阅读小部件章节以更好地理解这一点。

于 2019-12-02T05:58:21.610 回答