Skip to content

Instantly share code, notes, and snippets.

@onionhammer
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onionhammer/5bef227ffa5280f7da66 to your computer and use it in GitHub Desktop.
Save onionhammer/5bef227ffa5280f7da66 to your computer and use it in GitHub Desktop.
Example
# 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")
# 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