Power Pages: Read Site Settings in Liquid and JavaScript

A site setting is a configurable, named value that is used by website code to modify the behavior or visual style of the site. Typically when a developer creates the website code, they will reference site settings for various components to enable an end user to modify the setting values to alter the website without having to change the code, recompile, and redeploy the website.

Developers can use the site settings for storing configuration values for your script or liquid code. For example, when you do cloud flow integration with power pages. It requires cloud flow unique URL (Format: https://<powerpagessiteurl>/_api/cloudflow/v1.0/trigger/a3b78e3e-a04c-49ab-b1be-414474ec4cdd) to call the cloud flow. This URL has site name, which is different across different environment. So it’s a good practice to keep it in portal site setting and read it in your script or liquid code rather hard-coding it in your code and manually change it after each deployment.

Create Site Setting

I have created following site settings to keep cloud flow URLs.

Read Site Settings

To read the site setting in JavaScript or Liquid code, use the following syntax. You can write this code either on webpage or basic form or multi-step form or lists or web template or content snippet depends on your requirements.

{% assign UploadFlowURL = settings["PowerGuide/CloudFlowURL/UploadDocuments"] %}
{% assign DownloadFlowURL = settings["PowerGuide/CloudFlowURL/DownloadDocuments"] %}

shell.ajaxSafePost({
        type: "POST",
        contentType: "application/json",
        url: '{{UploadFlowURL}}';,
        data: JSON.stringify({"eventData":JSON.stringify({"Email": "abc@contoso.com", "File":{"name":"Report.pdf", "contentBytes":"base 64 encoded string"} })}),
        processData: false,
        global: false
    })
    .done(function (response) {
    
    })
    .fail(function(){
    });

Summary

In this blog post, you learned how site settings can also be used by developers to keep the configuration values and reuse in your script or liquid code. in Dataverse, you have a choice of Environment Variables to store the configuration values, however it doesn’t support in power pages. Therefore, site settings are the great way to store configuration values.

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

Leave a comment