In this article lets understand the basics of preparing and executing the fetchxml liquid template tag.
Lets first start with the basics of Liquid Tags and Template Tags.
What is a Liquid Tag:
- Liquid Tags make up the programming logic that tells templates what to do.
- Tags are wrapped in {% %}.
What is fetchxml Template tag:
- A Template tag is a category of Liquid Tags.
- fetchxml template tag, Allows user to query data from Dataverse, and render the results in a page.
- Following is the syntax:
{% fetchxml resultVariable %}
<!— Fetchxml query -->
...
{% endfetchxml %}
- ‘resultVariable ‘ in above sample, holds FetchXML query results and a few other attributes.
Now that you got the basics of fetchxml template tag, let’s proceed with its configuration and execution using an example.
Prepare and Execute the fetchxml template tag:
- I have a following Offer table in my Dataverse with 3 records. Let’s fetch these records and display them on the website’s Home page using the fetchxml template tag.

- First, generate the Offer table’s Fetch xml. To generate I used Advanced Find option. You can also use the Fetch XML Builder tool from XRM Toolbox.

- Generated Fetch XML looks as below:

- Now go to the Portals Designer and open the Home page in VSCode using Edit code option.
- Place the following fetchxml liquid tag:
{% fetchxml resultOffers %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="raj_offer">
<attribute name="raj_offerid" />
<attribute name="raj_name" />
<attribute name="statecode" />
<attribute name="raj_providername" />
<order attribute="raj_name" descending="false" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
</entity>
</fetch>
{% endfetchxml %}
<table>
<th>Name</th>
<th>Provider</th>
{% for offer in resultOffers.results.entities %}
<tr>
<td>{{ offer.raj_name }}</td>
<td>{{ offer.raj_providername }}</td>
</tr>
{% endfor %}
</table>
- Save, sync, and refresh the website. You should see the Offer records on Home page.

Understanding the fetchxml template tag code:
In the following fetchxml template tag,
- resultOffers : Variable holds the results of exeucted Fetch XML.
- resultOffers.results.entities : Offer records collection.
- <table>: Used to display offer records in a row and column format.
{% fetchxml resultOffers %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="raj_offer">
<attribute name="raj_offerid" />
<attribute name="raj_name" />
<attribute name="statecode" />
<attribute name="raj_providername" />
<order attribute="raj_name" descending="false" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
</entity>
</fetch>
{% endfetchxml %}
<table>
<th>Name</th>
<th>Provider</th>
{% for offer in resultOffers.results.entities %}
<tr>
<td>{{ offer.raj_name }}</td>
<td>{{ offer.raj_providername }}</td>
</tr>
{% endfor %}
Hope you now understand the basics of how to prepare and execute the FetchXML template tag.
🙂

![[Step by Step] Beginner : Create a PCF control and add it to a custom page](https://rajeevpentyala.com/wp-content/uploads/2024/12/image-49.png)
![[Step by Step] Using Custom Connectors in Copilot Studio](https://rajeevpentyala.com/wp-content/uploads/2024/10/record-ezgif.com-video-to-gif-converter-7.gif)
Leave a reply to Power Pages | Make FetchXML Liquid Template Tag reusable | Rajeev Pentyala – Microsoft Power Platform Cancel reply