Haskell 从文件渲染hamlet模板
假设我有以下模板代码:Haskell 从文件渲染hamlet模板,haskell,hamlet,Haskell,Hamlet,假设我有以下模板代码: $doctype 5 <html> <body> <h2>This is a test <div>Value of test variable: #{testVariable} $doctype 5 这是一个测试 测试变量的值:#{testVariable} 在文件mytemplate.hamlet中 如果不在源代码中显式粘贴模板,如何使用渲染 注意:此问题立即以问答式的方式得到回
$doctype 5
<html>
<body>
<h2>This is a test
<div>Value of test variable: #{testVariable}
$doctype 5
这是一个测试
测试变量的值:#{testVariable}
在文件mytemplate.hamlet
中
如果不在源代码中显式粘贴模板,如何使用渲染
注意:此问题立即以问答式的方式得到回答,因此故意不显示任何研究成果。有关如何将哈姆雷特
模板呈现为静态文件的信息,请参阅
唯一的主要区别是您需要使用Template Haskell的$(…)
操作符来计算由ShamlettFile
生成的Q Exp
。下面是一个完整的示例,假设您的mytemplate.hamlet
与Haskell文件位于同一目录中:
{-#语言准语言}
{-#语言重载字符串}
{-#语言模板haskell}
导入Text.Blaze.Html.Renderer.String(renderHtml)
导入Text.Blaze.Html
导入文本。哈姆雷特
--|主模板
renderTemplate::String->String
renderTemplateTestVariable=renderHtml($(shamletFile“mypage.hamlet”))
main=do
putStrLn$renderTemplate“foobar”
执行时,它会打印:
<!DOCTYPE html>
<html><body><h2>This is a test</h2>
<div>Value of test variable: foobar</div>
</body>
</html>
这是一个测试
测试变量的值:foobar
请注意,在应用程序中,您可能需要使用shamletFile
、xshamletFile
、hamletFile
或ihamletFile
。有关何时使用这些选项的信息,请参阅和