I have a shopping cart platform that has some variable already defined in a script tag... the one I need being product code.
to test the variable working, I put:
<script>
console.log(global_Current_ProductCode);
</script>
and in console, it returns the product code correctly depending on what product page is on, so far so good!
Next, I have another javascript code for a platform implementation (Power Reviews) and it looks like this:
<script>
POWERREVIEWS.display.render({
api_key: 'xxx-key-xxx',
locale: 'en_US',
merchant_group_id: 'xxxx',
merchant_id: 'xxxx',
page_id: 'global_Current_ProductCode',
review_wrapper_url: 'https://www.myurlhere.com/Articles.asp?ID=265',
components: {
ReviewSnippet: 'pr-reviewsnippet',
ReviewDisplay: 'pr-reviewdisplay'
}
});
</script>
(I added global_Current_ProductCode) and it just writes out: global_Current_ProductCode when page is rendered, so it's not calling the variable. But adding the variable to a console log DOES work. Am I missing something?
'document.write(global_Current_ProductCode);'you wrote it as a string literal. And your latest edit still is a string literal'global_Current_ProductCode'remove the quotes if you want JS to use the actual variable