I had a hard time using this snippet. It showed the content in the preview, but I could not access the modules to edit them.
So what I did, I tried to find a similar variable in the dev info. I found a more simple/native one there (maybe HubSpot added it later). So here is my solution, in case someone got the same issue: Simply change the
{% if request.postDict.inpageEditorUI %}
… to …
{% if is_in_editor %}
Hope this helps.