Skip to content
Franco Mussopower pages
Abstract swirling purple metallic form
Photograph · Creatvise / Unsplash
Guide No.032
SnippetCode Snippets · Liquid

Give everyone a chance to get featured – output random records from your Fetch XML in Power Pages

Mark Christie gave me an interesting challenge for the Scottish Summit build – with Scottish Summit championing inclusion and equality, let’s not be elitist about which speakers we feature.

Level
03CustomiseStage 3 of 4
Read
2 min
Includes
1 snippet · 1 figure
Written
May 2023

Mark Christie gave me an interesting challenge for the Scottish Summit build – with Scottish Summit championing inclusion and equality, let’s not be elitist about which speakers we feature. The previous speakers we feature should be selected at random. That way we give everyone an equal chance.

Power Pages
A list of previous speakers on the Scottish Summit portal with name, headshot and short bio. Each time the page is refreshed, the order is shuffled and 4 speakers are selected at random
Fig. 01A list of previous speakers on the Scottish Summit portal with name, headshot and short bio. Each time the page is refreshed, the order is shuffled and 4 speake…

TLDR; Here’s my solution:

Here’s the commented code if you’d like to repurpose for your own site:

Use liquid's Shuffle filter to output random resultsLiquid
{% comment %}Retrieve speakers for previous Scottish Summit events{% endcomment %}
{% fetchxml previous_speakers_query %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="msevtmgt_speaker">
    <attribute name="msevtmgt_speakerid" />
    <attribute name="msevtmgt_name" />
    <attribute name="ss_speakerimage" />
    <attribute name="msevtmgt_eventid" />
    <attribute name="msevtmgt_about" />
    <order attribute="msevtmgt_name" descending="false" />
    <filter type="and">
      <condition attribute="ss_speakerimage" operator="not-null" />
    </filter>
    <link-entity name="msevtmgt_speakerengagement" from="msevtmgt_speaker" to="msevtmgt_speakerid" link-type="inner" alias="af">
      <filter type="and">
        <condition attribute="msevtmgt_event" operator="in">
          <value uiname="Scottish Summit 2020" uitype="msevtmgt_event">{7BCEC1F7-25B7-EB11-8236-00224800319A}</value>
          <value uiname="Scottish Summit 2022" uitype="msevtmgt_event">{CB67AC6C-96AD-486A-9314-35FC9DBB0C28}</value>
          <value uiname="Scottish Summit Virtual 2021" uitype="msevtmgt_event">{79CEC1F7-25B7-EB11-8236-00224800319A}</value>
        </condition>
      </filter>
    </link-entity>
  </entity>
</fetch>
{% endfetchxml %}
 
{% comment %}Shuffle (randomise) the order of the results and store in a variable called speakers_shuffled{% endcomment %}
{% assign speakers_shuffled = previous_speakers_query.results.entities | shuffle %}
 
<section class="featured-content dark">
  <h2 class="h1">Previous <strong>Speakers</strong></h2>
  
  {% comment %}If one or more results is returned{% endcomment %}
  {% if speakers_shuffled.size > 0 %}
  <!-- Start of headshots -->
<div class="headshots">
{% comment %}Loop through the shuffled array of results{% endcomment %}
  {% for result in speakers_shuffled %}
  {% comment %}Output the first 4 items in the loop only{% endcomment %}
  {% if forloop.index <= 4 %}
    <!-- start the loop here -->
    <div class="headshot col-xs-12 col-sm-6 col-md-3">
        <div class="headshot-inner">
            {% if result.ss_speakerimage %}
            <img class="img-responsive img-circle" src="{{ result.ss_speakerimage }}" alt="Photo of {{ result.msevtmgt_name }}">
            {% endif %}
            <h4 class="h3">{{ result.msevtmgt_name }}</h4>
            <div class="small-meta">{{ result.msevtmgt_about | truncate: 300 }}</div>
        </div>
    </div>
    <!-- end the loop here -->
    {% endif %}
{% endfor %}
</div>
<!-- end of headshots -->
{% endif %}
</section>
Go deeper · Power Pages Mastery

This guide is one technique. The course is the method.

The course covers this in Level 3 · Advanced customisation: “Liquid templating for dynamic components”, alongside “Transforming out-of-the-box lists”. A structured programme distilled from dozens of real portal launches — from messy stakeholder requirements to successful go-live.

  • 6 weeks
  • 3 levels
  • Live training + video lessons
Where this fits
  1. Level 1Foundations
  2. Level 2Extending the platform
  3. Level 3Advanced customisation
    • Liquid templating for dynamic components
    • Transforming out-of-the-box lists
There is a knowledge gap when we go from traditional Power Apps work to Power Pages. Franco’s depth of platform knowledge, creative problem-solving, and understanding of web design makes using him to skill up a team a no-brainer.
Tyler Page — Director & Solution Architect — MCA Connect

Comments

No comments yet. Spotted a gotcha I missed? Say so below.

Leave a comment

Your email address won’t be published. Comments are moderated.

Consulting

Need a Power Pages build that editors love and brands survive?

I help teams design and build Power Pages sites with bespoke UX. Tell me about yours.

Search

Book a discovery call

30 minutes. Bring your trickiest Power Pages problem — I’ll tell you honestly whether I’m the right fit.