A local development environment with Salesforce Marketing Cloud
Working with Salesforce Marketing CloudPages can be painful—real painful. It takes away all the tools that make a developer productive and offers really nothing in return, but what if there was a way to take just a tiny bit of power back and work locally in your editor of choice? Well good news, there is. It may not make you like CloudPages any better, but it will make your life easier.
Enter a bunch of AMPscript functions
You will need no less than four AMPscript functions to make your life with Cloudpages more bearable. First we use Concat and GUID to load a url. GUID is used to escape caching, which wouldn’t be too good for development purposes. Then we do an HttpGet on this content followed by TreatAsContent. HttpGet obviously gets the file, but then we can add TreatAsContent. Now you can use AMPscript or SSJS right in your local dev files.
%%=TreatAsContent(HttpGet(Concat("https://INSTANCE.ngrok.io/my-dev-page.html?x=",GUID())))=%%
Once you have the above snippet for your site, you plop it into a cloud page, and from then on you can work locally in the editor of your choice.
Relevant documentation:
But wait! What’s this ngrok url?
I’m glad you asked, ngrok is a tool that will not only help you with SFMC Cloudpage madness, but other applications like local handshake with oauth server while building, or sharing content with others while you build locally, and probably a lot of other uses I can’t think of at the moment.
Download the ngrok tool, install it and point it at your local server. Don’t have a local server? Well if you are using node, you can type npx nodemon and boom, you have a server. This will work for any server obviously, so use what you like.
You can even use blocks, but you will need to copy paste those to Cloudpages (Copy paste Salesforce… Really? No pipelines). This also gets you around the insanely long caching times for Cloudpages of up to 5 minutes per save. Because we use a GUID, it’s instant, you just have to hit reload. Once you are all done you will have to copy the actual page into the cloud page and remove the snippet above.
For me this was pure awesomeness and greatly improved my productivity. Hopefully it helps someone else, and I should leave before I go into full rant mode.