Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang and AngularJS template conflict

Tags:

angularjs

go

I have a conflict with golang html/template and angularjs delimiters. I know that there is a method that lets to change delimiter in Go, but it does not work for me. Maybe it should be called before parsing of files? Could you please provide an example, how it should be implemented.

I found a lot of comments that AngularJS and Go should not have any conflict because they should be used separately. As I understand, Go should be used only for backend (REST). The question is, how AngularJS, HTML should be loaded? In this case, should I have to servers?

like image 474
emvein Avatar asked Dec 08 '13 22:12

emvein


3 Answers

you need to change the delimiters characters used that's all. I've had the same problem before on Beego because of the exact templating characters {{ }} and once I changed that to <<<>>> I managed to serve the html without any problems.

You basically need to call this function before you do any parsing: func (t *Template) Delims(left, right string) *Template

for more details:

http://golang.org/pkg/html/template/#Template.Delims

like image 108
ymg Avatar answered Sep 23 '22 13:09

ymg


The idea behind AngularJS is to have all the rendering process run on the client side.

If you follow this logic all along, you do not need any rendering on the server side (e.g : no call to template.Execute) when serving AngularJS html files, you simply have to serve static content.

like image 31
LeGEC Avatar answered Sep 25 '22 13:09

LeGEC


This worked for me.

indexTmpl = template.New("index.html").Delims("<<", ">>")
indexTmpl, _ = indexTmpl.ParseFiles("index.html")
like image 37
emvein Avatar answered Sep 26 '22 13:09

emvein