fix stack level too deep error when digesting recurisve templates