On Wednesday, January 4, 2017 at 7:09:48 PM UTC+2, Sathish VJ wrote:
>
> Is there a way to check if the previous value in the template range is 
> different from the current one?
>
> type Data struct {
> Value int32
> }
>
> var htmlTemplate = `{{range $i, $el := .}}
> {{$i}}:{{.Value}}: (is it diff from previous value, i.e. data[i-1])
> {{end}}`
>
> Intended use: to change the color of certain cells in a table if it is 
> different from that in previous row.
>
> code: https://play.golang.org/p/v-O_M4Rq4N
>


Hi,
add dummy element in slice at beginning and pass to template data[1:] and 
data:
https://play.golang.org/p/OnQPOJPsIp

I don't know is there a better way.
Djadala 
 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to