Last active
August 29, 2015 14:20
-
-
Save onionhammer/5bef227ffa5280f7da66 to your computer and use it in GitHub Desktop.
Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# layout.nim | |
import templates | |
proc render*(title, content: string): string = | |
tmpli html""" | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>$title</title> | |
<link rel="stylesheet" href="/styles.css"> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>$title</h1> | |
<div id="content"> | |
$content | |
</div> | |
</div> | |
</body> | |
</html> | |
""" | |
#view.nim | |
import templates | |
import layout | |
proc index(title: string): string = | |
tmpli html""" | |
<strong>This is from the page<strong> | |
""" | |
return layout.render(title, result) | |
echo index("My Page") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# layout.nim | |
import templates | |
template render*(title: string, content: stmt) = | |
template content_tmpl = content | |
tmpli html""" | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>$title</title> | |
<link rel="stylesheet" href="/styles.css"> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>$title</h1> | |
<div id="content"> | |
${ content_tmpl } | |
</div> | |
</div> | |
</body> | |
</html> | |
""" | |
# view.nim | |
import templates | |
import layout | |
proc index(title: string): string = | |
layout.render(title): | |
tmpl html""" | |
<strong>This is from the page<strong> | |
""" | |
echo index("My Page") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment