Yes, it is a "known" difficulty that nesting templates won't always work, because the compiler might substitute one template before another. I generally rely on macro on those cases.
But the fact that the following example don't work worries me more : import strformat import macros macro t1(): untyped = return quote do: var i = 10 echo fmt"i is {i}" # undeclared identifier: 'i' proc p1() = t1() when isMainModule: p1() Run