Shopify脚本标记变量

Shopify脚本标记变量,shopify,shopify-app,Shopify,Shopify App,如何通过管理api在脚本标记中获取客户变量?。我已经在liquid和js中尝试了{{customer.email}},我假设您正在通过脚本标签加载js。因此,液体变量{{customer}}对您不可用。你能做的就是通过你的js添加一个液体代码,这个代码会被Shopify解释,然后你就可以使用这些变量了。示例如下: cust_element = '{% if customer %}<span id="current-customer" data-customer-id="{{customer

如何通过管理api在脚本标记中获取客户变量?。我已经在liquid和js中尝试了{{customer.email}},我假设您正在通过脚本标签加载js。因此,液体变量{{customer}}对您不可用。你能做的就是通过你的js添加一个液体代码,这个代码会被Shopify解释,然后你就可以使用这些变量了。示例如下:

cust_element = '{% if customer %}<span id="current-customer" data-customer-id="{{customer.id}}" data-customer-name="{{customer.name}}" data-customer-email="{{customer.email}}"></span>{% endif %}';
var html = $.parseHTML(cust_element);
var $currentCustomer = $(html).find("#current-customer");
if ($currentCustomer.length > 0) {
  user_id = $currentCustomer.data("customer-id");
  name = $currentCustomer.data("customer-name");
  email = $currentCustomer.data("customer-email");
}

你确定这样行吗?我刚刚尝试过,但它似乎没有做任何事情。包含客户数据的元素需要存在于一个流动文件中,以便可以获取{customer}}。因此,span元素需要存在于一个液态文件中,以便Shopify对其进行解析,稍后javascript将读取这些值。您可以随时添加相同的内容。如果您可以等待,我可以分享一个php代码片段,您可以使用它。如果您可以,这将是一个巨大的帮助!似乎有很多问题要问如何做到这一点/如果可能的话,但答案不多,所以一个片段可以走很长的路