• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

how to pass javascript variable into liquid markup?

New Here ,
Aug 26, 2015 Aug 26, 2015

Copy link to clipboard

Copied

The question is I got the value from javascript:

  var customerID = document.getElementById("CustomerID").value;

now I want query the fistName, lastName from module data, based on that customerID variable.

{module_data resource="customers" version="v3" fields="id,firstName,lastName,titleType,customerTypeId,ratingTypeId" skip="0" limit="10" order="lastName" collection="selected-data"}

                          {% for item in selected-data.items %}

                          {% if item.id == 10393092%}

                                document.getElementById("CAT_Custom_15").setAttribute("value","{{item.titleType.label}}");

                    document.getElementById("CAT_Custom_14").setAttribute("value","{{item.firstName}}");

                    document.getElementById("CAT_Custom_4").setAttribute("value","{{item.lastName}}");

                            {% endif %}

                        {% endfor %}

How should I write the where condition?

Whne I assign instant value that 10393092 in my code above. It is working fine. but I need assign the variable equal to item.id. Anyone can help? Thank you so much

Views

5.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 22, 2016 Nov 22, 2016

Copy link to clipboard

Copied

Hi Janj,

Unfortunately you cannot do that. Reason is liquid is processed at server side and you will be fetching the content from the browser DOM using var customerID = document.getElementById("CustomerID").value;

When the page loads, the content from server (for module_data) have already processed and after that the DOM elements will load resulting in no data passed to liquid if else condition.

At the moment there is no way to send javascript data to the server for module_data.

Regards,

Gaurav Aggarwal

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2016 Nov 22, 2016

Copy link to clipboard

Copied

LATEST

To add to the above.. You will have customer ID - They logged in so you have this and you were looking to get it with javascript then pass it to Liquid.

You can just get the value yourself with liquid for the customer ID and do it all in liquid.

And Gaurav has said "At the moment there is no way" But its server side vs client and in these use cases its a never.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines