I thought of another way to solve that doesn't produce side effect templates.
import macros
import tables
var overrides {.compiletime.} = initTable[string,string]()
macro override(a, b: untyped) : untyped =
var x = genSym(nskTemplate)
overrides[a.strVal] = x.strVal
result = quote do:
template `x`() : untyped =
`b`
macro section(a, b : untyped) : untyped =
let aStr = a.strVal
if aStr in overrides:
let templateName = ident(overrides[aStr])
result = quote do:
`templateName`()
else:
result = b
override redbox:
echo "Hello"
section redbox:
echo "Goodbye"
section whatever:
echo "Hello World!"
Run