Base64 encoding and Base64 decode using Liquid in Dynamics 365/ PowerApps portals

For training and consulting, write to us at info@xrmforyou.com
Follow my blog for more interesting topics on Dynamics 365 and Portals

As I have been working on liquids a lot lately, I am amazed by the simple and yet powerful language which allows me to do so much without drop of a sweat. And then came this requirement.

I have to base64 encode and decode using Liquid. After having explored liquid so much, this was kind of stuff I never tried before in liquid. I thought after all with the kind of operators available in liquid, this would be a cakewalk. There must be a filter out there which allows me to do the same. Did a bit of search and surprisingly found nothing. But I was not ready to give up though.

So I started trying these constructs –

This is my base64 encoded string : {{ “abcde” | base64_encode }}

This is my base64 decoded string: {{ “YWJjZGVk” | base64_decode }}

Nothing worked out! I did find some references of bas64_encode and base64_decode filters in some liquid implementations but unfortunately they doesn’t work in portals.

But I have to meet the requirement. What should I do? It’s turn for me now to fall back to the good old JavaScript to do the same.

So I used the javascript btoa function for base64 encoding and atob function for base64 decoding.

Sample code below for reference.

{% assign account = entities.account[‘<accountid>’] %};

<div class="jumbotron" id="div_base64">

<script>

document.write(btoa("{{ account.crb08_encodefield }}")); // crb08_encodedfield is field in account entity

</script>

</div>

Similarly you can use atob function for decoding.

And that is where liquid failed me. Don’t worry liquid, you are still my dear friend.

Hope this helps!

For more interesting topics like this, follow my blog using follow button on top left of page. It’s all about Dynamics 365 and Portals.

Debajit Dutta

(Business Solutions MVP)