“在Shopify的Liquid中,是否可以将数据保存到本地存储或Cookie中?”

huangapple go评论57阅读模式
英文:

is that available save a data at the localstorage or cookie in liquid with shopify?

问题

我想要在本地存储或Cookie中保存一些数据。

我知道如何使用JavaScript而不是Liquid保存数据。

我在Shopify上找到一些答案,表示这不可行。

有其他方法吗?

使用Liquid语言在浏览器的本地存储或Cookie中保存数据。

英文:

i want to save some data at the localstorage or cookie

i know that how to save data with javascript not liquid

i found some answer at the shopify that this isn't available

Is there any other way?

Save data at the browser's localstorage or cookie with liquid language

答案1

得分: 1

你可以在包含在 script 标签中的 .liquid 主题文件中使用 JavaScript,或者创建一个 JS 文件并包含它:

内联 HTML JavaScript(layout/templates/sections/snippet 文件):

<script>
localStorage.setItem('namespace', 'value')
</script>

JS 文件(在您的资产文件夹中):

// my-file.js
localStorage.setItem('namespace', 'value')

这将要求您在相关的 liquid 文件中包含资产:

{{ 'my-file.js' | asset_url | script_tag }}
英文:

You can use javascript in your .liquid theme files included in a script tag or create a JS file and include it:

Inline HTML Javascript (layout/templates/sections/snippet files):

&lt;script&gt;
localStorage.setItem(&#39;namespace&#39;, &#39;value&#39;)
&lt;/script&gt;

JS file (in your assets folder)

// my-file.js
localStorage.setItem(&#39;namespace&#39;, &#39;value&#39;)

this would require you to include the asset in the relevant liquid file:

{{ &#39;my-file.js&#39; | asset_url | script_tag }}

huangapple
  • 本文由 发表于 2023年6月8日 08:58:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定