英文:
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):
<script>
localStorage.setItem('namespace', 'value')
</script>
JS file (in your assets folder)
// my-file.js
localStorage.setItem('namespace', 'value')
this would require you to include the asset in the relevant liquid file:
{{ 'my-file.js' | asset_url | script_tag }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论