Exercise: Display a List of Accounts Using Liquid in Power Pages

Exercise: Display a List of Accounts Using Liquid in Power Pages

In this hands-on lab, you learn how to access Dataverse data using Liquid code.

The goal of this exercise is to:

• Enter Liquid code as page content
• Access Dataverse data using Liquid
• Use conditional statements to display available data

You will create a page that lists active accounts and shows the total number of accounts.

Step 1: Open Power Pages Design Studio

Sign in to Power Pages and open the website you want to edit.

Step 2: Create the Suppliers Webpage

In the Pages workspace, select + Page, enter "Suppliers" as the page name, choose the blank template, and add the page.

Step 3: Add HTML and Liquid Code

On the Suppliers page, add a text component and replace its placeholder with the following HTML and Liquid:

<h2>List of accounts</h2>
{% entityview logical_name:'account', name:'Active Accounts' %}
<p>We have {{ entityview.total_records }} accounts.</p>
<ul>
{% for account in entityview.records -%}
<li>{{ account.name }}
  {% if account.telephone1 %}
  (<a href="tel:{{ account.telephone1 }}">{{ account.telephone1 }}</a>)
  {% endif %}
</li>
{% endfor %}
</ul>
{% endentityview %}

Code Explanation

<h2>List of accounts</h2>
Displays the heading text on the page.
{% entityview logical_name:'account', name:'Active Accounts' %}
Loads the Active Accounts Dataverse view from the Account table. Only records defined by this view are retrieved.
We have {{ entityview.total_records }} accounts.
Shows the total number of account records returned by the view.
{% for account in entityview.records %}
statement starts a loop that iterates through each Account record returned by the referenced Dataverse view. During every iteration, the variable account represents a single row from the Account table, allowing access to its fields such as name or phone number. The hyphen before %} trims extra whitespace from the generated HTML output, ensuring cleaner and more compact page rendering in Power Pages.
{{ account.name }}
Displays the name of the current account.
{% if account.telephone1 %}
Checks whether the account has a phone number. Prevents empty values from being displayed.
<a href="tel:{{ account.telephone1 }}">
Renders the phone number as a clickable link for calling.
{% endfor %}
Ends the loop after all account records are processed.
{% endentityview %}
Closes the entityview block and completes data rendering.
Note: Table permissions must allow read access to the Account table. Without permissions, the list will appear empty.

Step 4: Preview the Results

After syncing, preview the page in Design Studio and in a browser. Initially, you will see "We have 0 accounts." because no table permissions exist yet.

Step 5: Add Table Permissions

To allow account records to be displayed, add global read permissions for the Account table:

• In Set up workspace, open Table Permissions
• Add new permission:
• Name: Suppliers
• Table: Account
• Access type: Global access
• Permission: Read
• Add roles: Anonymous users and Authenticated users
• Save and preview again
Once permissions are in place, the list of accounts should display.

What You Learned

• How to embed Liquid within page content using the text editor
• How to use the entityview tag to list Dataverse data
• How to display counts and loop through records
• Why table permissions are needed in Power Pages

This exercise shows practical Liquid usage for listing active accounts securely.

Comments

Popular posts from this blog

Part 1: Creating Code Apps in Power Apps - A step-by-step guide (with real errors I faced & how I fixed them)

Calling Microsoft Graph API from Power Automate Using Azure App Services – Step-by-Step Guide

Step-by-Step Guide: Power Automate Custom Connector Using Graph API from Azure App Service