-1

I have an if else block in my template. when else if is true it is rendered always empty as if else or else if is not there

here is my template

in this case in this case, it renders nothing enter image description here

And also I am using text/template because html/template send the page completely empty

//the template
    <script>
                  {{if.PassChange}}
                  swal("{{.Lang.Success}}", "{{.Lang.PleaseLogin}}", "success")
                  {{end}}
                  {{if.UserExists}}
                  swal("{{.Lang.Fail}}", "{{.Lang.AlreadyMember}}", "error")
                  {{end}}
    </script>




//rendering part
    BasePath.Get("/", func(w http.ResponseWriter, r *http.Request) {
        tpl.ExecResponse(w, struct{Lang map[string]string ; UserExists bool}{Lang:lang.GetLang(r),UserExists:true})
    })
nikoss
  • 3,254
  • 2
  • 26
  • 40
  • The images and particularly the second are difficult to read. Please paste the text into the question. Also, what library are you using to render the template? – Charlie Tumahai Dec 21 '16 at 05:06
  • @MellowMarmot just updated – nikoss Dec 21 '16 at 05:11
  • the smart people of the galaxy who voted negative would you please share your incredible knowledge with us why you think this is a stupid question – nikoss Dec 22 '16 at 02:42

1 Answers1

2

If you print the error from executing the template, you will find that the template cannot evaluate the field PassChange. One possible fix is to add a PassChange field to the struct.

tpl.ExecResponse(w, struct{PassChange bool; Lang map[string]string ; UserExists bool}{Lang:lang.GetLang(r),UserExists:true})
Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242