In my previous article (Prepare and Execute FetchXML Liquid Template Tag), I have explained the basics of preparing and executing the fetchxml liquid template tag.

In that example, I placed the Offers ‘FetchXML template tag’ inside the Home page code as shown below.

But what if we need to display Offers records on multiple web pages? One option is to repeat the same ‘fetchxml template tag’ on all pages, which is redundant.

In this article, I will explain how to prepare the ‘fetchxml template tag’ once and reuse it across web pages.

To reuse the ‘fetchxml template tag’, we need to create a new Web Template with the ‘fetchxml template tag’.

Create a Web Template with ‘fetchxml template tag’:

  • Go to Power Pages Management app.
  • Click on Web Templates > New
  • Provide Name and Website.
  • Copy the existing fetchxml template tag from Home page code and paste it in the Source textbox of the Web Template record.
  • Save the Web Template.
  • Web Template saves as Fetch Offers

Configure ‘Table Permissions’ for Offers table:

To render the Offer records using this approach require you to configure Table Permissions for Offers table as mentioned in this article.

Now that we’ve created a Web Template with the ‘fetchxml template tag’ and added Table Permissions, let’s use it in Web Pages.

Use the ‘fetchxml template tag’ Web Template in Webpage:

  • Open the Home web page code in vscode.
  • Remove the existing ‘fetchxml template tag’.
  • Now use the {% include %} to refer the Fetch Offers Web Template created in the above step.
{% include 'Fetch Offers' %}
  • Save the Home web page
  • Save, sync, and refresh the website. You should see the Offer records on Home page.
  • Similarly, if you need to display the Offers on another web page, simply use the {% include ‘Fetch Offers’ %} tag.

🙂

Advertisements
Advertisements

2 responses to “Power Pages | Make FetchXML Liquid Reusable”

  1. Power Pages | FetchXML Liquid not showing records | Rajeev Pentyala - Microsoft Power Platform Avatar

    […] my previous article (Make FetchXML Liquid Template Tag reusable), I have explained how to reuse fetchxml liquid template tag using a Web Template […]

  2. Power Pages | Web templates as components | Rajeev Pentyala - Microsoft Power Platform Avatar

    […] my previous article (Make FetchXML Liquid Template Tag reusable), I have explained how to reuse fetchxml liquid template tag using a Web Template […]

Leave a reply to Power Pages | FetchXML Liquid not showing records | Rajeev Pentyala – Microsoft Power Platform Cancel reply