Skip to content

Instantly share code, notes, and snippets.

@XULRunner42
Created June 1, 2011 17:55
Show Gist options
  • Save XULRunner42/1002881 to your computer and use it in GitHub Desktop.
Save XULRunner42/1002881 to your computer and use it in GitHub Desktop.
Product Listing Page Template
#html, body {
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
width:622px;
height: 100%;
margin: auto;
}
#content {
padding-top: 10px;
}
.productlist { margin: 0px; padding: 0px;
border: 1px solid gray;
width: 620px; clear: bottom;
}
.product { border: 1px solid gray;
margin: 7px; padding: 2px; height: 100%;
background-color: #ddd; width: 140px;
display: block; float: left;
margin-right: 0px;
}
.product a:link {
display: block; background-color: #4cf;
padding: 2px 4px; border: 1px solid #2aa;
font-family: sans-serif; font-size: .8em;
text-align: center; height: 2.5em;
}
.product strong {
display: block; margin: 0px;
}
.product img { width: 132px; height: 132px; margin: 4px;
padding: 0px; margin-top: 6px; margin-bottom: 0px;
}
.pageindex { padding: 2px;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
width: 264px;
height: 39px;
border: 1px solid gray;
margin: 6px auto;
}
.pagelink { background-color: #0af;
border: 1px solid #4cf; margin: 1px 2px 0px 2px;
text-align: center; width: 22px; padding: 8px;
float: left; font-family: sans-serif;
display: block;
}
a:link, a:hover a:visited {
color: white;
}
page
1
2
3
4
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>Featured Products</title>
<link href="/css/main.css" rel="stylesheet" type="text/css" media="all"/>
{{!<script type="text/javascript" src="javascript/main.js"></script>}}
</head>
<body>
<div id="content">
<div class="productlist">
{{#products}}
<div class="product">
<strong><a href="{{url}}">{{title}}</a></strong>
<img src="{{img}}"/>
</div>
{{/products}}
<br style="clear: both"/>
</div>
<div class="pageindex">
{{#pages}}
<span class="pagelink">
<a href="/page/{{page}}">{{page}}</a>
</span>
{{/pages}}
</div>
</div>
</body> </html>
url title img
/product/1 Steaming Pile #1 http://example.us/pile-shit.jpg
/product/2 Steaming Pile #2 http://example.us/pile-shit.jpg
/product/3 Steaming Pile #3 http://example.us/pile-shit.jpg
package main
import (
"github.com/hoisie/web.go"
"github.com/hoisie/mustache.go"
)
func getProducts() (ret []map[string]string) {
ret = []map[string]string{ {
"url": "/product/1",
"title":"Steaming Pile #1",
"img": "http://example.us/pile-shit.jpg",
}, {
"url": "/product/2",
"title":"Steaming Pile #2",
"img": "http://example.us/pile-shit.jpg",
}, {
"url": "/product/4",
"title":"Lookin' Good Template",
"img": "http://nerdland.info/template.png",
}, {
"url": "/product/3",
"title":"Steaming Pile #3",
"img": "http://example.us/pile-shit.jpg",
},
}
return ret
}
func getPages() (ret []map[string]string) {
// there are so many pages,
ret = []map[string]string{
{ "page": "1" },
{ "page": "2" },
{ "page": "3" },
{ "page": "4" },
{ "page": "5" },
{ "page": "6" },
}
return ret
}
func renderPage(ctx *web.Context, val string) {
products := getProducts()
pages := getPages()
in := map[string]interface{} {
"products": products,
"pages": pages,
}
out := mustache.Render("{{>productpage}}", in)
ctx.WriteString(out)
}
func index(ctx *web.Context, val string) {
renderPage(ctx, "1")
}
func renderProduct(ctx *web.Context, val string) {
out := "not implemented product view<br/><a href='/'>back to front</a>"
ctx.WriteString(out)
}
func main() {
web.Get("/product/(.*)", renderProduct)
web.Get("/page/(.*)", renderPage)
web.Get("/(.*)", index)
web.Run("0.0.0.0:8080")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment