PHP templates fix

Fixes #1375.  PR for easier discussion and organization.