Use output of query loop in code block

I have rolled my own events CPT and the customer has asked for a monthly calendar view alongside the list of upcoming events. I found FullCalendar (, which is working great. I have a calendar, but I need to give it upcoming events. I could write the SQL and embed it in the code block I’m using to embed FullCalendar, but it seems like that’s a second source of problems. If the query loop changes, I, or someone else, has to also remember to update the SQL in the code block.

Any idea if there’s a way to use the output of the query loop inside the codeblock?