CRM-12750 - Smarty - Restore patches from CRM-5890