I see, the reason you get the undeclared identifier error is because of scopes. When you define a var in a for loop it can't be accessed from outside. This is a simplified example: for i in 0 .. 10: var x = 1 echo x # Error: undeclared identifier: 'x' Run
Second reason is that templates have [hygiene](https://nim-lang.org/docs/manual.html#templates-hygiene-in-templates) which means variables defined in a template can't be accessed from the outside. There are two solutions to this, injecting the variables or marking the template with the {.dirty.} Run pragma which removes all hygiene. But the scope thing is the one that's limiting you in this case. I can't come up with anything from the top of my head right now but I'll try to figure something out :/