我希望在Magento中有一个功能,我可以向管理员添加文本字段,并允许用户添加一个代码片段,其中包含变量的占位符。
在运行时,我将通过getStoreConfig获取代码片段,并将变量/占位符替换为我需要的值。
除了如何添加变量和替换之外,我已经成功完成了所有工作。
所以我在admin等中创建配置时不需要帮助。
一个例子是用户在配置字段中输入以下内容:
<script>
alert('{{amazing_value}}');
</script>
然后在我的模板中我会这样做:
$codeSnippet = Mage::getStoreConfig('path_to_config');
$amazingValue = "This will replace the variable";
// Something here :) (this bit im not sure about where the variable is translated)
echo $codeSnippet
那时的输出是:
<script>
alert('This will replace the variable');
</script>
答案 0 :(得分:0)
在“Something here”区域,您可以尝试:
$codeSnippet = str_replace("{{amazing_value}}",$amazingValue,$codeSnippet);