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 / Use Liquid Variable (g...
Power Pages
Unanswered

Use Liquid Variable (generated in html) to javascript

(0) ShareShare
ReportReport
Posted on by 16
Hello!
I am building a Power Page and I need to reference in my Javascript (advanced web page options) a variable generated in Liquid code in the HTML.
 
HTML code (liquid)
 
{% fetchxml articles_search %}
      <fetch version= "1.0" output-format= "xml-platform" mapping="logical" distinct="false" no-lock="true" >
  <entity name="knowledgearticle">
    <attribute name="title" alias="titulo_articulo" />
    <attribute name="content" alias="contenido_articulo" />
    <attribute name="knowledgearticleid" alias="id_articulo" />
  </entity>
</fetch>
{% endfetchxml %}
 
{% assign articles_for_search = articles_search.results.entities %}
 
<script type="text/javascript">
var articles_for_searching = {{articles_for_search|json}};
</script>
 
 
Javascript code
 
inputSearch.onkeyup = e => {
let userData = e.target.value;
let emptyArray = [];
 
if (userData) {
emptyArray = articles_for_searching.filter(data => {
return data
.toLocaleLowerCase()
.startsWith(userData.toLocaleLowerCase());
});
        console.log(emptyArray)
        }}
 
 
But when I test the page running the console.log, I get the following error:
Juanse_1-1688568224209.png

 

I need to call the variable in js somehow or what am I doing wrong?
 
Thanks!
Categories:
I have the same question (0)
  • Lucas001 Profile Picture
    2,434 Super User 2025 Season 2 on at

    Hi @Juanse,

     

    from what I see the problem relies in the line:

    var articles_for_searching = {{articles_for_search|json}};

    What happens if you just console log after that line?

     

    I usually use a webteamplate on another page to fetch the XML and refer to that page from whereever I want to use the JSON data.

    You can reference the text from the website containing only JSON and use JSON.parse() to afterwards further manipulate it.

    {% fetchxml YourEntity %}
    <fetch>
     <entity name="YourEntityName">
     <attribute name="Attr1" />
     <attribute name="Attr2" /> 
     </entity>
    </fetch>
    {% endfetchxml %}
    
    <!-- Creating a JSON Element -->
    [
    {% for item in YourEntity.results.entities %}
     {
     "id": "{{ item.id }}",
     "name": "{{ item.name }}"
     }{% unless forloop.last %}, {% endunless %}
    {% endfor %}
    ]

     

     

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
Fubar Profile Picture

Fubar 89 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 75

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard