how to pass javascript variable into liquid markup?
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
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
Copy link to clipboard
Copied
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.
