A query such as that will not work when viewed as a template. You need to insert the template into a new (or another test) file, and then check whether the query is valid or not.
In that regard, it’s very useful to make the template into a command and bind that to a key to trigger the template. In my test setup I’ve got an intermediate template named “xTemplate” which I’ve bound to Ctrl + Cmd + X. This I change to my liking, and then insert the template into a test file until I’m satisfied, and move it over to the real template where I want that new functionality.