yea, it would be great if someone could help me on this, i read & search but still couldn’t find the answer this couple of days, maybe i’m still quite noobs in go.
what I want is, to create custom unique id for each div in post loop in the template, because i have a pop-up modal for each post.
what i usually do in php is just declare $i = 1; outside the loop, then in the loop just use <div id="hidden<?php echo $i++; ?>" >
so it have unique id for each post
i tried with adding variable like this outside the loop {{ $unique := 1 }}
then in the loop add this {{ add $unique 1 }}
but the variable just echo 2 and doesnt add up for each post.
am i missing something here? i also try throw the $unique var to new var but still it just echoing same sum.
Does this variable still work in 0.14? If I use it in single.html, I don’t get an error message but it breaks the generation of the page (below .UniqueId, no content is generated).
Edit: Nevermind, found on Github that it’s called UniqueID now. Just keep my post here in case someone else also runs into this.
According to the documentation, {{ .UniqueId }} is now deprecated and should be replaced by {{ .File.UniqueID }}
Please also note that files with similar names (but in different folders) may have the same UniqueID (using .File.UniqueIDmay fix this issue, not sure, the ticket is not clear on this point)