Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 从文件渲染hamlet模板_Haskell_Hamlet - Fatal编程技术网

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
。有关何时使用这些选项的信息,请参阅和