web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to define an array...
Power Pages
Answered

How to define an array for liquid?

(0) ShareShare
ReportReport
Posted on by 214

How to define an array for liquid?

 

{% assign fetchAttributes = [  'firstname', 'name'] %}
{% for att in fetchAttributes %}
  {{ att }} -

{% endfor %}


results in: Liquid error: Value cannot be null. Parameter name: input

{% assign fetchAttributes = 'firstname', 'name' %}
results in:  f -   i -   r -   s -   t -   n -   a -   m -   e -
(funny, but useless 😉


In docs I find only a use case :

https://docs.microsoft.com/en-us/powerapps/maker/portals/liquid/liquid-types#array

 

Thanks for help

AndKan

Categories:
I have the same question (0)
  • H V Profile Picture
    1,510 on at

    Hi @AndKanPA 

    Please try below code:

    {% assign fetchAttributes = "firstname,name" | split:',' %}
    {% for att in fetchAttributes %}
     {{ att }} -
    {% endfor %}

    --------------------------
    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people! 

  • AndKanPA Profile Picture
    214 on at

    Thank you, works fine.

     

    Is it possible to create an associative array?

    Like:

    key1=>value1, key2=>value2

     

    What I want do is: Add entity attributes and their names into an array.

    Then create a table header from that.

     

    Entity attribut is cr847_firstname, cr847_name and so on.

    Table header should be firstname, name and so on.

     

    "cr847_firstname"=>"firstname"

    "cr847_name" => "name"

     

     

     

  • Verified answer
    H V Profile Picture
    1,510 on at

    Hi @AndKanPA 

    You need to create different array for different key and iterate through for loop.

    Below code will help you to achive your requirement:

    {% assign attributesHeader = "Header1,Header2" | split:',' %}
    {% assign attributesFirstName = "John,Mike" | split:',' %}
    {% assign attributesLastName = "Losen,Smith" | split:',' %}
    
    <table>
     <tr>
     {% for obj in attributesHeader %}
     <th>{{ obj }}</th>
     {% endfor %}
     </tr>
     
     {% for obj in attributesFirstName %}
     <tr>
     <td>{{ obj }}</td>
     <td>{{ attributesLastName[forloop.index0] }}</td>
     </tr>
     {% endfor %}
    </table>

     --------------------------
    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!

  • AndKanPA Profile Picture
    214 on at

    Yes, that's seems the only way ...

    I defined 3 arrays to have optional sorting or not:

     

    <!-- getting parameters from url -->
    {% assign order = request.params['order'] | default: 'cr847_name' %}
    {% assign orderdir = request.params['orderdir'] | default: 'ASC' %}
    
    <!-- use orderir in fetch query -->
    
    
    <!-- entity columns/attributes themeselves -->
    {% assign columns = "cr847_firstname,cr847_name,cr847_city" | split:"," %}
    <!-- Header names -->
    {% assign colnames = "Firstname,Name,City" | split:"," %}
    <!-- Sortable headers. Note: 'x' is neccessary for index counting. firstname is not sortable -->
    {% assign sortAttributes = "x,cr847_name,cr847_city" | split:"," %}
    
    <table class="table">
    <thead>
     <tr>
    {% for col in columns %}
     <th data-logicalname="{{ col }}}">
     <!-- if column is sortable add a link -->
     {% if columns[forloop.index0] == sortAttributes[forloop.index0] %}
     <a href="{{ request.path_and_query | add_query:'order', sortAttributes[forloop.index0] | add_query: 'orderdir', orderdir}}">
     {{ colnames[forloop.index0] }}
     {% if order==sortAttributes[forloop.index0] %}
     {{ orderdir_icon }}
     {% else %}
     {{order}}!={{sortAttributes[forloop.index0]}}
     {% endif %}
     </a>
     {% else %}
     {{ colnames[forloop.index0] }}
     {% endif %}
     </th>
    {% endfor %}
    </tr>
    </thead>
    <tbody>
    {% for result in query.results.entities %}
    <tr>
     ...

     

    Have fun,
    AndKan.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
DP_Prabh Profile Picture

DP_Prabh 51

#2
rezarizvii Profile Picture

rezarizvii 35

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 35 Most Valuable Professional

Last 30 days Overall leaderboard