BUILDING SOLID LIQUID SKILLS - TEMPLATE AND CDS TAGS

TEMPLATE TAGS

Template tags control the output of a template in various ways, and allow the combination of multiple templates into a single output.

FETCHXML

It allows users to query data from CDS currently cached* within portal.

{% fetchxml accomplishments %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="mshied_accomplishments">
    <attribute name="mshied_accomplishmentsid" />
    <attribute name="mshied_name" />
    <attribute name="mshied_student" />
    <attribute name="mshied_accomplishmenttype" />
    <attribute name="mshied_description" />
    <order attribute="mshied_name" descending="false" />
    <filter type="and">
      <condition attribute="statecode" operator="eq" value="0" />
      <condition attribute="mshied_student" operator="eq" value="{{user.id}}" />
    </filter>
  </entity>
</fetch>
{% endfetchxml %}

In order to access the query results, use the results object then the entities collection. (Entities = Records).

{% assign accomplishments_results = accomplishments.results.entities %}

Once a collection is retrieved, you can use it within a for loop. (Please disregard HTML included in the sample).

<table class="table table-striped">
  <thead>
    <tr>
      <th>Accomplishment</th>
      <th>Type</th>
    </tr>
  </thead> 
  {% for accomplishment in accomplishments_results %} 
  <tr> 
    <td>{{ accomplishment.mshied_name }}</td> 
    <td>{{ accomplishment.mshied_accomplishmenttype.label }}</td> 
  </tr> 
  {% endfor %} 
</table> 

OUTPUT

Fetchxml.png

INCLUDE

Adds the contents of another template into another, by name. The include tag accepts parameters using the following notation. e.g. {% include 'My Template' a:x, b:y %}

{% include 'FetchXML Course History'  studentid:user.id %}
<table class="table table-striped">
  <thead>
    <tr>
      <th>Course</th>
      <th>Grade</th>
    </tr>
  </thead> 
  {% for course_history in course_history_results %} 
  <tr> 
    <td>{{ course_history.mshied_name }}</td> 
    <td>{{ course_history.mshied_lettergrade }}</td> 
  </tr> 
  {% endfor %} 
</table> 
Include.png

INCLUDE (WITH TEMPLATE THAT USES JOINS)

Here is the body of the web template named ‘FetchXML Scholarship‘.

{% fetchxml scholarship %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="mshied_scholarshipapplicant">
    <attribute name="mshied_scholarshipapplicantid" />
    <attribute name="mshied_applicationstatecode" />
    <attribute name="mshied_scholarship" />
    <attribute name="mshied_submissiondate" />
    <attribute name="mshied_offermadedate" />
    <attribute name="mshied_offerdeadlinedate" />
    <attribute name="mshied_offeraccepteddate" />
    <filter type="and">
      <condition attribute="statecode" operator="eq" value="0" />
      <condition attribute="mshied_applicant" operator="eq" value="{{studentid}}" />
    </filter>
    <link-entity name="mshied_scholarship" from="mshied_scholarshipid" to="mshied_scholarship" link-type="inner" alias="scholarship">
      <attribute name="mshied_amount" />
      <attribute name="mshied_name" />
    </link-entity>
  </entity>
</fetch>


{% endfetchxml %}
{% assign scholarship_results = scholarship.results.entities %}

Note that the resultset uses different notation to access query attributes surfaced through query join.

{% include 'FetchXML Scholarship'  studentid:user.id %}
<table class="table table-striped">
  <thead>
    <tr>
      <th>Scholarship Name</th>
      <th>Submitted On</th>
      <th>Potential Amount</th>
    </tr>
  </thead> 
  {% for scholarship in scholarship_results %} 
  <tr> 
    <td>{{ scholarship['scholarship.mshied_name'] }}</td> 
    <td>{{ scholarship.mshied_submissiondate | date: 'MMMM dd, yyyy' }}</td> 
    <td>$ {{ scholarship['scholarship.mshied_amount'] | round:2 }}</td> 
  </tr> 
  {% endfor %} 
</table> 
Include-Join.png

CDS TAGS

Power Apps entity tags are used to load and display Power Apps data, or use other Power Apps portals framework services. These tags are Power Apps-specific extensions to the Liquid language.

EDITABLE

Renders a given Power Apps portals CMS object as editable on the portal, for users with content editing permission for that object. Editable objects include pagesnippets, and weblinks.

Content-Snippet.png

Here is a sample of the Editable tag code referencing the “Sample Snippet“.

<h5>Editable - Sample Snippet</h5>
{% editable snippets 'Sample Snippet' type: 'html' %}

OUTPUT

Editable.png

ENTITY LIST

Entity List can be referenced by name or id. For complete OOB Entity List features use the entity_list web template. e.g. {% include 'entity_list' key: page.adx_entitylist.id %}

{% entitylist name:'University List' %}
  {% entityview %}
  <div class="col-md-12">
    Loaded entity view with {{ entityview.total_records }} total records.
  </div>
  {% assign accounts = entityview.records %}
  <table class="table table-striped">
    <thead>
      <tr>
        <th>Institution Name</th>
      </tr>
    </thead> 
    {% for account in accounts %}
    <tr><td>{{ account.name }}</td></tr>
    {% endfor %}
  </table>
  {% endentityview %}
{% endentitylist %}

OUTPUT

Entity List.png

ENTITY VIEW

Entity view can be used to reference an existing CDS entity view. Also note the use of Batch command in this example.

{% entityview logical_name:'contact', name:"Active Contacts" %}
  <div class="col-md-12">
    Loaded entity view with {{ entityview.total_records }} total records.
  </div>
  {% assign batches = entityview.records | batch: 4 %}
  {% for batch in batches %}
  <div class="col-md-4">
    <ul class="nav nav-pills nav-stacked">
      {% for contact in batch %}
      <li class="{% cycle 'active', '', '', ''%}"><a href="#">{{ contact.fullname }}</a></li>
      {% endfor %}
    </ul>
  </div>
  {% endfor %}
{% endentityview %}
Entity View.png

ENTITY FORM

<h5>Entity Form</h5>
{% entityform name: 'Sample Account Form' %}
Entity Form.png
Victor DantasComment