cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

How to define an array for liquid?

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Impactful Individual
Impactful Individual

Re: How to define an array for liquid?

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!

View solution in original post

4 REPLIES 4
Highlighted
Impactful Individual
Impactful Individual

Re: How to define an array for liquid?

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! 

Highlighted
Helper III
Helper III

Re: How to define an array for liquid?

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"

 

 

 

Highlighted
Impactful Individual
Impactful Individual

Re: How to define an array for liquid?

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!

View solution in original post

Highlighted
Helper III
Helper III

Re: How to define an array for liquid?

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.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (7,718)