Spent too long getting this to work so I've made a short github gist and have included it here so people don't have to ?
https://gist.github.com/benbyford/ada3a229501c769880b0aa2b13276d3e
I've added this php instead of the normal page in my templates when a /cal url query is preset.