Generate page content before initialising smarty (Bug #1337626)

Change-Id: I4b5fb0da8567e95fd9c0e57806baca835b50764e
Signed-off-by: Nathan Lewis <nathan.lewis@totaralms.com>
Signed-off-by: Robert Lyon <robertl@catalyst.net.nz>