AEM 6.3, Touch UI. I have a simple template and page component, described in detail at Layout Mode Not Showing Up. When a page using that template is locked, the page cannot be edited, due to a javascript error:

Once this error occurs, the globalbar buttons, like Edit, Preview, Unlock, and Page Information are all non-functional.
I have seen it happen with other templates too, sometimes with the same error happening in page.js
In this particular example, the page template component looks like this:
<html>
<%@include file="/libs/foundation/global.jsp" %>
<cq:include script="/libs/wcm/core/components/init/init.jsp"/>
<body>
<cq:include path="" resourceType="/libs/foundation/components/title"/>
<h3>Layout:</h3>
<cq:include path="pagecontent/layout" resourceType="wcm/foundation/components/responsivegrid"/>
</body>
</html>
I've also seen templates where this doesn't happen (like the We.Retail pages), so something is clearly missing in these templates.
Does anyone know what I need to do, or what needs to be in this template to avoid this error?