N
N
Nube2018-02-27 16:55:03
go
Nube, 2018-02-27 16:55:03

Styles (css) are reset, reasons?

Good time of the day! I divided the index page into 3 templates such as header , content ,footer. Now when I want to open another page like index2 with header, content2,footer templates. Styles don't work when the header is the same as the one used on the first page.
For the first page I use - http.HandleFunc("/",render.IndexRender) and the next pages I load directly
using ExecuteTemplate.
Here is my example.

var index	= template.Must(template.ParseFiles(Index,Head,Foot))
var login	= template.Must(template.ParseFiles(Login,iHead,Foot))
var cab 	= template.Must(template.ParseFiles(Cab,Head,Foot))

/*****************************************************/
func templateRender(w http.ResponseWriter,t template.Template,name string, page *Page) {
  err:=t.ExecuteTemplate(w,name,page)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
  }

}


func SwitchTemplate(w http.ResponseWriter,namePage  string,page *Page){
  switch namePage {
  case "index":
    templateRender(w,*index,namePage,page)
  case "login":
    templateRender(w,*login,namePage,page)
  case "cab":
    templateRender(w,*cab,namePage,page)

  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petro Kvartsianyi, 2019-01-23
@Patrick12

All I can say is don't render the page on the server with go, it's difficult and not convenient

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question