2016-12-21 2 views
-2

템플릿에 if else 블록이 있습니다. else if에 해당하는 경우 else 또는 else if 여기가 골란 템플릿이 제대로 작동하지 않습니다.

되지 않습니다이 경우 내 템플릿

in this case 경우로 비어 항상 렌더링, 그것은 아무것도에게 enter image description here

를 렌더링하지 않습니다 또한 나는 text/template을 사용하면 html/template 페이지가 완전히 비어 있기 때문에

//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}) 
    }) 
+0

이미지와 특히 두 번째 이미지는 읽기가 어렵습니다. 질문에 텍스트를 붙여 넣으십시오. 또한 어떤 라이브러리를 사용하여 템플릿을 렌더링합니까? –

+0

@MellowMarmot 방금 – nikoss

+0

부정적인 투표를 한 은하계의 똑똑한 사람들은 너와 내가 우리와 함께 너의 믿을 수없는 지식을 나눠 주길 바래. – nikoss

답변

3

템플릿을 실행하여 오류를 인쇄하면 서식 파일에서 PassChange 필드를 평가할 수 없습니다. 한 가지 가능한 해결 방법은 구조체에 PassChange 필드를 추가하는 것입니다.

tpl.ExecResponse(w, struct{PassChange bool; Lang map[string]string ; UserExists bool}{Lang:lang.GetLang(r),UserExists:true}) 
+0

만약 내가 할 수 있다면 어리석은 질문이라고 생각하는 이유는 무엇인가? – nikoss

관련 문제