DEV Community

Andrew Elans
Andrew Elans

Posted on

Power Pages: Content Snippets with a HACK part 1

Power Pages is meant to be a low-code platform for building web sites from built-in components. But what if you like me dislike the pre-built components and want to have full control over what you implement and how?

For example, build a Single Page Application without built-in PowerApps dependencies, ref. my earlier series of posts here in progress.

Default Power Pages Management apps

When you create environment and a Power Pages site, you get provisioned default model-driven apps to manage your website:

  1. One is a portal management app accessed at make.powerpages.microsoft.com and explained here;
  2. Another is a configuration app at make.powerapps.com -> Apps -> Power Pages Management explained here, where you can manage your content snippets and web files.

Power Pages Management app at make.powerapps.com

Content snippets in this app that look like this:

Image description

Content snippets are just html fragments that you can paste into your website. A simple snippet may be as simple as <h1>Frame Agreements</h1>.

All snippets sit in a Dataverse table Content Snippet (mspp_contentsnippet) and can be accessed through:

  1. make.powerapps.com -> Solutions -> Default Solution -> Search for Content Snippet

Image description

  1. In a web browser with query https://your-env.api.crm4.dynamics.com/api/data/v9.2/mspp_contentsnippets

Image description

If you get HTTP ERROR 401 when calling this query, you need first to go to https://your-env.api.crm4.dynamics.com and authenticate with your user credentials (you need to have admin role).

Difference between Dataverse Security Roles and Power Pages Web Roles

How are Dataverse Teams with Security Roles different from Power Pages Web Roles?

Dataverse Teams with Security Roles are applicable if you use MSAL library for authentication with Dataverse (explained in my SPA series), i.e. dependencies are fully controlled by you from scratch.

Power Pages Web Roles are applicable when you build a portal with low-code principle as designed by Microsoft.

Since I'm building an SPA with full control over dependencies, I will not be using Web Roles.

Why would you need another custom Content Snippets table

Here is a typical scenario. Let's say you have a Frame Agreements page where you have both metadata of the agreements and documents to download. We would establish two user teams and render the Frame Agreement page differently:

  1. For procurement personnel with the functionality to download documents.
  2. For others in the organization that would be able to see only metadata of the documents without download button.

Default scenario with one Content Snippets table

We would have to allow Read Content Snippets (mspp_contentsnippet) to both groups. We may have two different content snippets: one with download functionality for procurement, another is without - for others.

However, main downside is that anyone from group Others with coding knowledge can easily get all content snippets since they have access to mspp_contentsnippets, render the download functionality and access the files (in case we also don't have access control on Azure Storage).

How to fix

We can create another custom Content Snippets table where we save the download functionality snippet. This custom table will be allowed to be read by Procurement personnel only.

Challenges to overcome

We can easily create a new table with snippets. However when saving html in this custom table, html tags will be stripped by Power Apps. So instead of having <button>Download</button> you will see just a stripped text Download when saved.

Moreover, we would like to see the prettified html content in this custom table as we see in the default app like this:

Image description

To fix this we would need to create a custom Power Pages Management app and that's what I will do next...

Top comments (0)