Visual Studio Code has excellent support for creating Liquid Templates for Azure API Management or Logic Apps. With the right extensions it can provide both code completion and a live preview which displays the output of your template while you are editing it. With a split editor you can see both the input, the transform and the output at the same time.
- Install the following extensions:
- Name the template file yourname.liquid and the input file yourname.liquid.json
- For Azure API Management, enclose your JSON in a "body" object. For Logic Apps, use a "content" object
- Run (Ctrl+Shift+P) "Shopify Liquid: Open Preview to the Side (Plaintext)"
- Run (Ctrl+Shift+P) "Change Language Mode" when selecting the output and choose e.g. XML or JSON to get color coding
These extensions use the original Shopify Liquid while Microsoft uses the .NET port DotLiquid which has some differences. The main one is that the first letter of filters are lower case in the original version and defaults to upper case in DotLiquid, so before using the template somewhere like API Management we need to convert the case. If there are more than a few filters you might want to use this RegEx method:
- Find (Ctrl+F): \| (\S)
- Make sure "Use Regular Expression" is enabled (Alt+R)
- Select All Occurrences of Find Match (Alt+Enter)
- Run (Ctrl+Shift+P): "Transform to uppercase"
That is all, have a good day!