What is the meaning of ^{...} in ".hamlet" files

97 Views Asked by At

In this ".hamlet" code I would like to know what is the meaning of ^{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}
1

There are 1 best solutions below

0
On

That example you have been linked might be slightly confusing because you don't see the copyright function anywhere. copyright is just another function. You can use the ^{..} function to embed another widget within one. This example might help you:

#!/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

And on executing it:

$ stack hamlet.hs
"<body><p>Hello world</p>\n<p>Copyright by the SPJ</p>\n</body>\n"

I would recommend you to go through the widgets chapter to get a better understanding of this.