GrapeJS does indeed modify your MJML code when you open your custom template. This is quite common, but there are workarounds to fix it.
I have written an explanation on how to prevent GrapeJS from automatically changing your code for your exact situation. If you use {% verbatim %} before opening your Twig block, and close it after the last {% endverbatim %}, GrapeJS will handle your code correctly.