Golang Templates

186 views
Skip to first unread message

Ali Hassan

unread,
Jul 15, 2020, 10:14:51 AM7/15/20
to golang-nuts
<div class="horzontialList" id="List">
{{range .}}
  {{if ne .Symbol " "}}
           <span>{{.Symbol}}</span>
         {{end}}
   {{end}}


var div=document.getElementById('List');
var point = div.getElementsByTagName('span');

console
.log(point[0].innerHTML)


Actual Output: Empty string
Excepted Output: Y 
How to resolve this 

Brian Candler

unread,
Jul 15, 2020, 10:33:49 AM7/15/20
to golang-nuts
What language is that code written in?  It looks more like Javascript than Go to me.

If you have a problem with some Go code, please can you show the Go code - ideally as a self-contained runnable example at play.golang.org
Message has been deleted
Message has been deleted

Ali Hassan

unread,
Jul 16, 2020, 4:26:25 AM7/16/20
to golang-nuts

Ali Hassan

unread,
Jul 16, 2020, 4:27:06 AM7/16/20
to golang-nuts


On Wednesday, July 15, 2020 at 3:14:51 PM UTC+5, Ali Hassan wrote:

Brian Candler

unread,
Jul 16, 2020, 7:37:29 AM7/16/20
to golang-nuts
The next thing to do  is to boil this down to a standalone test case in the golang playground.

Are you saying the template is not being expanded correctly at line 155? https://github.com/ali2210/WizDwarf/blob/master/main.go#L155

Are you sure the value of LifeCode is what you expect? Try printing it at that point.

If it is, then write a small program which sets LifeCode to that fixed value, and expands the template.  If that works, then you know the problem is somewhere else.  If it doesn't work, then you know the problem is with template expansion and someone can help you debug it, because they have the code in the go playground where they can easily edit and test it.
Reply all
Reply to author
Forward
0 new messages