Fix bake templates to generate functioning code.

Closes #2776