cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Portals won't let me populate a HTML table based on liquid for loop

I have a strange issue which is preventing me from populating a HTML table with rows based on the results of a for loop. Does anyone know if there is a setting that stops this from working? I am ultimately looking to loop through an array of results from a FetchXML query, which isn't working, it seems that Portals is not printing the results of the for loop when in a HTML table. To simplify the analysis I have taken FetchXML out of scope and are simply attempting to loop through five iterations, populating i in a table row, as you can see below the code is very straightforward;

 

paulx3_1-1638935414996.png

 

When this code runs the table rows aren't populated, but the second loop (starting line 115) works fine. 

paulx3_2-1638935469448.png

here is the generated HTML

paulx3_3-1638935504553.png

 

Is there a site setting which could preventing this code from working? I've seen examples (such as this) which show that this technique should work ok. 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
chleverenz
Power Participant
Power Participant

Hi @Anonymous ,

i found the reason: when you put the code in the adx_copy field the content is altered while saving. If you reload the whole page you can see, that the savingprocess moved the code like this:

<br>
{% for x in (1..5) -%}
{{ x }} <br>
{% endfor -%}


    {%- for i in (1..5) -%}

    {%- endfor -%}
<table>
<tbody><tr><td>Banana Pi</td></tr><tr><td>
        {{ i }}
</td></tr></tbody></table>
so, completely clear that is does not work as the forloop was moved out while saving.
 
Nevertheless: as you had to write this code in each and every adx_copy field i would highly recommend to create a specific webtemplate and either include it or better use it as your pagetemplate. You could copy the webtemplate of the used pagetemplate to a new one, add your code and make a new pagetemplate with that one. Then every page using that pagetemplate will use your table.
 
Thanks again for posting this problem. This really tells me not to trust the saving and the html editor...
Have fun,
  Christian
Have fun,
Christian
----------------------
Please do not forget to leave feedback if this post helped you. Already giving kudos is a great way of feedback when the post was helpful.
Comments on how the answer could be improved are welcome, too.

View solution in original post

8 REPLIES 8
chleverenz
Power Participant
Power Participant

Hi @Anonymous ,

for me this renders perfectly:

chleverenz_0-1638953454857.png

 

the code:

<br>
Here 1
<br>
<table>
<thead>
<tr><td>Banana</td></tr>
{% for i in (1..5) -%}
<tr><td>{{ i }} </td></tr>
{% endfor -%}
</thead>
<tbody>
</tbody>
</table>
<br>

Here 2
<br>
{% for x in (1..5) -%}
{{ x }} <br>
{% endfor -%}
 
May be, its a cache issue. Try to reset the cache under <portalurl>/_services/about while logged in as an admin or just add an arbitrary parameter to the request like /?z=42 . This helps sometimes preventing caching on the whole lane 🙂
Hope this helps,
  Christian
 
PS is not an error but a hint: i try to balance the {% stuff. {%- means no linebreak and i try to use it in the opening AND the closing tag if i use it. Just adopted to this because otherwise i was always confused about my code where it produces newlines 🙂
Have fun,
Christian
----------------------
Please do not forget to leave feedback if this post helped you. Already giving kudos is a great way of feedback when the post was helpful.
Comments on how the answer could be improved are welcome, too.
Anonymous
Not applicable

Thanks for checking, this is very strange, tried your code and it definately doesn't work on my portal (despite multiple cache resets)

 

Code

 

paulx3_0-1638953815442.png

 

result, nothing but the table header

 

paulx3_1-1638953881355.png

 

Makes me think that its a site setting or some kind of security feature thats preventing this from working

chleverenz
Power Participant
Power Participant

Hi @Anonymous ,

where are you using the liquid? in the header or footer template or in the page template? If the latter, are you using it with or without header/footerrendering?

No idea, whether this makes a diffrence. I tried as a page template with header/footer rendering.

Even if unlikely: could it be that the i is somehow used already? i tried assigning i a string before the loop but it still works...

This is really strange. I know of no setting telling me, that x is a valid name whilst i not 🙂

 

Have you copied your code to notepad or something? May be, you have strange characters in it (unlikekly, because my copied code does not work, too)

 

Sorry not to be able to assist,

  Christian

 

PS just checked: also ok, when i do not use header and footer in the page template. As we say in germany: i am at the end with my latin skills 🙂

Have fun,
Christian
----------------------
Please do not forget to leave feedback if this post helped you. Already giving kudos is a great way of feedback when the post was helpful.
Comments on how the answer could be improved are welcome, too.
Anonymous
Not applicable

very strange, my code is just placed within a webpage. I am using the starter portal template and have tried a few different page templates. I've even created a brand new web page just to test out your code again and it still won't render the rows when they are in html table. 

paulx3_0-1638955902065.png

 

if the rows aren't in a HTML table then they work fine, ie:

paulx3_1-1638956084401.png

 

produces;

paulx3_2-1638956098794.png

 

 

chleverenz
Power Participant
Power Participant

Hi @Anonymous 

this is weired 🙂 - i put the stuff now in the copy field of the page and the table does not render as well. I usually place this code directly in the web-template itself

Just to make it even more strange: If i include my previously created template, it works:

Holla
<br>
Here 1.9
<br>
{% assign i = "Cucumber" %}
<table>
<thead>
<tr><td>Banana</td></tr>
    {% for i in (1..5) -%}
        <tr><td>{{ i }}</td></tr>
    {%- endfor %}
</thead>
<tbody>
</tbody>
</table>
<br>

Here 2
<br>
{% for x in (1..5) -%}
{{ x }} <br>
{% endfor -%}
<table>
<thead>
<tr><td>Banana Pi</td></tr>
    {% for i in (1..5) -%}
        <tr><td>{{ i }}</td></tr>
    {%- endfor %}
</thead>
<tbody>
</tbody>
</table>

Not the included one:
{% include "cl test template" %}
chleverenz_0-1638957018066.png

 

This smells like a bug 🙂

PS interestingly, the word "Cucumber" which was assigned to the variable i seems to be used in the youtput. As if the forloop with the "i" does not exist. 

Thanks for pointing this out - will keep this in my brain as a challenge 🙂

Have fun,
Christian
----------------------
Please do not forget to leave feedback if this post helped you. Already giving kudos is a great way of feedback when the post was helpful.
Comments on how the answer could be improved are welcome, too.
chleverenz
Power Participant
Power Participant

Hi @Anonymous ,

i found the reason: when you put the code in the adx_copy field the content is altered while saving. If you reload the whole page you can see, that the savingprocess moved the code like this:

<br>
{% for x in (1..5) -%}
{{ x }} <br>
{% endfor -%}


    {%- for i in (1..5) -%}

    {%- endfor -%}
<table>
<tbody><tr><td>Banana Pi</td></tr><tr><td>
        {{ i }}
</td></tr></tbody></table>
so, completely clear that is does not work as the forloop was moved out while saving.
 
Nevertheless: as you had to write this code in each and every adx_copy field i would highly recommend to create a specific webtemplate and either include it or better use it as your pagetemplate. You could copy the webtemplate of the used pagetemplate to a new one, add your code and make a new pagetemplate with that one. Then every page using that pagetemplate will use your table.
 
Thanks again for posting this problem. This really tells me not to trust the saving and the html editor...
Have fun,
  Christian
Have fun,
Christian
----------------------
Please do not forget to leave feedback if this post helped you. Already giving kudos is a great way of feedback when the post was helpful.
Comments on how the answer could be improved are welcome, too.
Anonymous
Not applicable

Thank you so much for this @chleverenz , you have been very helpful! I am new to Portals, so didn't realise that it wasn't a good idea to add this kind of code to the copy section. Adding to a web template definately works, so i will use this approach going forward

chleverenz
Power Participant
Power Participant

Hi @Anonymous 

you're welcome. Thanks for accepting the response as a solution.

Have fun,

  Christian

Have fun,
Christian
----------------------
Please do not forget to leave feedback if this post helped you. Already giving kudos is a great way of feedback when the post was helpful.
Comments on how the answer could be improved are welcome, too.

Helpful resources

Announcements

Summer of Solutions | Week 3 Results | Win free tickets to the Power Platform Conference

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 1: Community MembersSolutionsSuper UsersSolutionsPower Pages @Inogic  1   @ragavanrajan  2 @aofosu  1 @Jcook  1Open  @OliverRodrigues  1Open  @Lucas001  1Open Open    Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 2: Community MembersSolutionsSuper UsersSolutionsPower Pages @taraubianca25  2 @EmadBeshai  2 @ALP2  2@Fubar 2 @ekluth1  2@ragavanrajan 1 @mandela  1@OliverRodrigues 1 @Ajlan  1Open   @elishafxx  1    @TA_Jeremy  1    @helio1981  1       Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower PagesInogic2@EmadBeshai 6Ajlan1@ragavanrajan 4CraigWarnholtz1@Fubar 4  @Jcook 3  @OliverRodrigues2  

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

  On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Top Kudoed Authors
Users online (5,022)