Implement layout templating, tests ok