Commit c921bc39 authored by Paul's avatar Paul

Update to blocks

parent c166833e
......@@ -4,7 +4,8 @@ Templates are awesome, they let you render HTML on the fly with the
results of your query. Simple Web was inspired by Simple Template and
was built to exploit this pack. But Simple Web is not Simple
Template, so we encourage you to [read their docs](http://www.swi-prolog.org/pack/list?p=simple_template) for a better
understanding of how to use them.
understanding of how to use them. This version requires at least version
1.3.0 as it is using the blocks feature.
# Simple Web Templates
......
......@@ -14,12 +14,16 @@
sw:route('/', _Request) :-
post_titles(Titles),
reply_template(blog, data{titles: Titles}).
reply_template(blog, data{ titles: Titles
, title: 'Blog'
}
).
sw:route(root(Name), _Request) :-
blog_post(Name, Content),
Data = data{ name: Name
, content: Content
, title: 'Post'
},
reply_template(post, Data).
......
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="static/favicon.ico">
<title>{{= title }}</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
{{ slot }}
</div>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="static/favicon.ico">
<title>Blog</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
{{ block base }}
<h1>Blog Posts</h1>
<ul class="list-group">
{{ each titles, title}}<a href="/{{= title}}">
<li class="list-group-item">{{= title}}</li>
</a>{{ end }}
</ul>
</div>
</body>
</html>
{{ end }}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="static/favicon.ico">
<title>Post</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
{{ block base }}
<h1>{{= name }}</h1>
<p>{{= content}}</p>
<p><a href="/">←Back</a></p>
</div>
</body>
</html>
{{ end }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment