shijuvar/go-web

Rendering CSS in public folder (chapter 5, example htmltemp).

Closed this issue · 2 comments

Hi,
I tried to add a css file in public folder as suggested at page 85. Here are the modified the base.html template (templates folder):
`{{define "base"}}

{{template "head" .}} {{template "body" .}} {{end}}`

and the layers.css file:

body { color: purple; background-color: #d8da3d }
But the css rendering doesn't work!
Could you please suggest a working code?
Thanks in advance,
Danilo

Hi, the issue is how you served your file..i built something off the example too and this is how i served my css folder:
r := mux.NewRouter().StrictSlash(false)
fs := http.FileServer(http.Dir("templates"))
r.PathPrefix("/css/").Handler(http.StripPrefix("/css/",
http.FileServer(http.Dir("templates/css/"))))

my css file is placed in a "css" folder which is placed in a "template" folder(templates/css) and the template folder is the same folder as the main.go file like so:
template/css/file.css
main.go

I hope this helps.

Thanks a lot.