Added protection against invalid templates from half-displaying, simplified method for creating local PHP vars when compiling template