Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't know the meaning of templates/article.html #10

Open
pkumza opened this issue Oct 16, 2017 · 2 comments
Open

Don't know the meaning of templates/article.html #10

pkumza opened this issue Oct 16, 2017 · 2 comments

Comments

@pkumza
Copy link

pkumza commented Oct 16, 2017

I ran the example and don't know the meaning of templates/article.html.

As I view http://localhost:8080/article, I got

Title: Html5 Article Engine index template: Hi, this is index.html

What's the relationship of this page with templates/article.html???

@ShawnOY
Copy link

ShawnOY commented Mar 7, 2018

I have no idea why article not work fine, I try to modify and it's work.

base.html

Title: {{ .title }}

index template: {{template "body" .}}

article.html

{{define "body"}}
Hi {{ .title }}, this is article template
{{end}}

index.html

{{define "body"}}
Hi, this is index.html
{{end}}

example.go

package main

import (
	"github.com/gin-contrib/multitemplate"
	"github.com/gin-gonic/gin"
)

func createMyRender() multitemplate.Renderer {
	r := multitemplate.NewRenderer()
	r.AddFromFiles("index", "templates/base.html", "templates/index.html")
	r.AddFromFiles("article", "templates/base.html", "templates/article.html")
	return r
}

func main() {
	router := gin.Default()
	router.HTMLRender = createMyRender()
	router.GET("/", func(c *gin.Context) {
		c.HTML(200, "index", gin.H{
			"title": "Html5 Template Engine",
		})
	})
	router.GET("/article", func(c *gin.Context) {
		c.HTML(200, "article", gin.H{
			"title": "Html5 Article Engine",
		})
	})
	router.Run(":8080")
}

@nordbit
Copy link

nordbit commented Sep 30, 2020

After 3 years still not corrected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants