Fix crash when no global context is supplied, no handler context is supplied, and a layout template is being used

Fix crash when no global context is supplied, no handler context is supplied, and a layout template is being used. Couldn't find a decent way to add a test, but the coverage is still 100% :) 

Fixes #16