moving before-render middleware handling

handing before-render middleware before doing mergeContext to ensure any changes to `template.data` and `template.locals` will be reflected on the context.