State engine with inline templates