Magento static block javascript variable

Magento static block javascript variable

本文关键字:variable javascript block static Magento      更新时间:2023-09-26

我已经学习Magento一个星期了,我坚持Magento静态块。我正在静态块内容中编写一些代码。带线条:

"Testing Magento variables {{config path="general/store_information/name"}}"

我完美地得到了我的商店名称。我的问题是我已经尝试过几次将该变量分配给javascript问候变量,但总是失败。也许有人可以帮助我写什么而不是??????。如果其他句子,我将使用它。

<html>
<body>
"Testing Magento variables {{config path="general/store_information/name"}}"
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() 
   {
      var greeting = ??????????;
   }
</script>

</body>
</html>

如果您尝试将商店名称分配给变量;

var greeting = '{{config path="general/store_information/name"}}';

您还可以在admin中创建自己的自定义变量:系统>自定义变量(从顶部菜单),并在cms块或页面中调用这些变量;

{{customvar code="my_custom_var"}}

顺便说一下,您不应该将 html 和正文标签添加到 cms 块中。

不确定,但请尝试将文本换行...

"Testing Magento variables {{config path="general/store_information/name"}}"

如。。。

"Testing Magento variables <span id="name">{{config path="general/store_information/name"}}</span>"

然后,您可以在函数中将其引用为...

var greeting = document.getElementById("name").innerText;