I’ve read Custom Output Formats a couple of times and I’m confused. Here’s what I’ve done so far:
I created mediaTypes and outputFormats in config.toml
[mediaTypes]
[mediaTypes."text/x-php"]
suffixes = ["php"]
[outputFormats]
[outputFormats.phpFormat]
baseName = "index"
isPlainText = false
mediaType = "text/x-php"
I created /content/contact/index.php file. For simplicity’s sake, it contains only phpinfo() nested in main block, but let’s pretend that there are actual contact form routines, plus some PHP includes: 
{{ define "main" }}
<?php
phpinfo();
?>
{{ end }}
In /layouts/contact I created baseof.php:
<!DOCTYPE html>
<html>
{{- partial "head.html" . -}}
<body>
{{- partial "header.html" . -}}
<div id="content">
{{- block "main" . }}{{- end }}
</div>
{{- partial "footer.html" . -}}
</body>
</html>
And a simple index.php:
{{ define "main" }}
{{ .Content }}
{{ end }}
The phpinfo() executes properly in /contact/, but Hugo’s magical incantations fail, so at the beginning and the end of the /contact/ page I’m greeted with {{ define "main" }} and {{ end }}. Neither the head, header nor footer are loaded.
To be honest, the existence of /layouts/contact/baseof.php and /layouts/contact/index.php doesn’t seem to affect /contact/index.php in any way. It executes fine with or without them.
What am I doing wrong?