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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Apply Filters to Liqui...
Power Pages
Unanswered

Apply Filters to Liquid Code

(0) ShareShare
ReportReport
Posted on by 16

Hi, I am new to Power Pages and Liquid Code. I need to filter all Articles in a Category. I tried this, but did not get the expected result.

The desired result of the following code is to get the list of the Articles in the Category "Credit Card" and then display their Titles and Content.


{% assign category_articles = knowledge.articles | knowledge.categories == 'Credit Card' %}

{% for article in category_articles %}

<h3 class= "title-question"> {{ article.title}} </h3>
<div class= "answer"> {{ article.content}} </div>

{% endfor %}


Can you help me? Thank you!

Categories:
I have the same question (0)
  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at

    Hi @Juanse ,

     

    Can you please try this one:

    {% assign category_articles = knowledge.articles | where: 'categories', 'Credit Card' %}
    
    {% for article in category_articles %}
    
    <h3 class= "title-question"> {{ article.title}} </h3>
    <div class= "answer"> {{ article.content}} </div>
    
    {% endfor %}

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Juanse Profile Picture
    16 on at

    Hi @saudali_25 , thank you for your response.

    I tried to apply that code, but now I get the following error on the screen:

     

    Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.KnowledgeArticlesDrop' cannot be converted to type 'System.Collections.IEnumerable'.

     

    Do you know what is the reason?

  • Lucas001 Profile Picture
    2,429 Super User 2025 Season 2 on at

    Hi @Juanse,

     

    of which type is your .knowledgeArticlesDrop column? Is it a choice?

    You are currently trying to display a "string" inside your h3 as an example. Depending on your column type that can be a problem. You have to make sure that the value is either a string or can b at least converted to a string.

     

    What I like to do in such cases is, trying to display another column to see if the column has a problem or if there is a problem with the connection itself.

  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at

    Hi @Juanse ,

     

    Apologies for late response. 

     

    As per exception you shared, it seems to be an issue with type casting. I'm unsure about the columns type you're trying to get and apply filtration. I have shared liquid assuming 'category' column to exist on same table. If you can explain a little bit more about your table and columns type, I will try to update liquid accordingly.

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Juanse Profile Picture
    16 on at

    Thank you very much for your answers, they are always very helpful.
    I detail better my objective.
    The web page that I build, has the following section where frequently asked questions about a category and then, about the sub-category that is selected.

     

    Juanse_0-1687362031977.png

     

    I need to filter by each selected category the associated items. I generated this code for that, but it does not work correctly. 

     

    Juanse_1-1687362819883.png

     

    In Dataverse there is a main table called "Category".

    Juanse_2-1687363184012.png

     

    Each Category can have one or several associated categories (Sub-Categories).

     

    Juanse_3-1687363437659.png

     

    Each Sub-Category can have one or several associated items.

    Juanse_4-1687363591710.png

    Extra information: In the Relationships section of the Category table there is a relationship between both tables. But it is not clear to me how to invoke this relationship from my source code.

     

    Juanse_5-1687364121103.png

     

  • Juanse Profile Picture
    16 on at

    I added all the information that I thought was relevant. I would be very grateful if you could help me with this. @saudali_25 @Lucas001 

  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at

    Hi @Juanse ,

     

    Can you please try following: 

     

    1. Double-check the configuration of the lookup column in the Dataverse entity. Ensure that the lookup column is properly set up with the correct relationship and target entity.

    2. Temporarily modify your code to filter based on a different column (e.g., a non-lookup column) to see if the error persists. This can help identify whether the issue is specific to the lookup column or if there's a more general problem with the Liquid code or data retrieval.

    3. Try to build and execute a query from Rest Builder and test if you're using correct relationship.

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

     

  • Lucas001 Profile Picture
    2,429 Super User 2025 Season 2 on at

    Hi @Juanse,

     

    first I would try to do what @saudali_25  mentioned.

    If I understand you correct you have a main category and a sub category which is necessary to be filtered depending on the chosen main category and so on, is my assumption correct?

     

    If it is than you would have to make cascading lookups: https://www.youtube.com/watch?v=2ufzeKcy8D0.

    As you only have one condition you can set it up with multiple tables and lookup filed between the table as explained in the video.

     

    In maybe easier solution for your problem would be a multistep form: https://www.youtube.com/watch?v=E285u3v9dqU

     

    Hope that helps.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard