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

How to link CSS with template in box #158

Open
sujit-baniya opened this issue May 13, 2020 · 0 comments
Open

How to link CSS with template in box #158

sujit-baniya opened this issue May 13, 2020 · 0 comments

Comments

@sujit-baniya
Copy link

My folder structure is:

/template
    /layouts
        master.html
    page.html
/public
    /assets
        app.css

I've tried following code to link template and CSS/JS/IMAGES inside public folder usin go rice.

router := gin.Default()
	box := rice.MustFindBox("public")
	cssFileServer := http.StripPrefix("/", http.FileServer(box.HTTPBox()))
	http.Handle("/pbc", cssFileServer)
	//new template engine
	basic := gorice.NewWithConfig(rice.MustFindBox("templates"), goview.Config{
		Root:      "templates",
		Extension: ".html",
		Master:    "layouts/master",
		Partials:  []string{"partials/ad"},
		Funcs: template.FuncMap{
			"copy": func() string {
				return time.Now().Format("2006")
			},
		},
		DisableCache: true,
	})
	router.HTMLRender = ginview.Wrap(basic)

	router.GET("/", func(ctx *gin.Context) {
		// `HTML()` is a helper func to deal with multiple TemplateEngine's.
		// It detects the suitable TemplateEngine for each path automatically.
		ginview.HTML(ctx, http.StatusOK, "index", gin.H{
			"title": "Frontend title!",
		})
	})

	http.ListenAndServe(":8080", router)

I tried to run above query but unable to link CSS file in template
What will be the link for CSS that would be used in template file?
Will it be
/public/assets/app.css OR
/pbc/assets/app.css OR
/assets/app.css

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

1 participant