Last active
August 29, 2015 13:55
-
-
Save techslides/8760665 to your computer and use it in GitHub Desktop.
Passing variable for custom title to layout.html template in Martini
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
| //inside Martini GET function m.Get("/", func(r render.Render) {... | |
| //newmap := map[string]interface{}{"metatitle": "this is custom title for SEO", "posts": posts} | |
| //r.HTML(200, "posts", newmap) | |
| //layout.tmpl | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>{{.metatitle}}</title> | |
| <!-- Add custom CSS here --> | |
| <link href="/css/main.css" rel="stylesheet"> | |
| </head> | |
| <body> | |
| {{yield}} | |
| <!-- JavaScript --> | |
| <script src="http://code.jquery.com/jquery-latest.js"></script> | |
| <script src="/js/main.js"></script> | |
| </body> | |
| </html> | |
| //posts.tmpl | |
| {{range .posts}} | |
| <h3><a href="/{{ .Id }}">{{ .Title }}</a></h3> | |
| <small>{{.Created | formatTime}}</small> | |
| <div>{{ .Body }}</div> | |
| {{end}} | |
| <h2>Create a Post</h2> | |
| <form action="/" method="POST"> | |
| <input type="text" name="Title" placeholder="Title" /><br> | |
| <textarea name="Body"></textarea><br> | |
| <input type="submit" value="submit"/> | |
| </form> | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Learn more about this code here: http://techslides.com/simple-app-with-go-martini-gorp-and-mysql/