1

我想在 Magento 中有一个功能,我可以在其中向管理员添加文本字段,并允许用户添加一个代码片段,其中将有一个变量的占位符。

在运行时,我将通过 getStoreConfig 获取代码片段并将变量/占位符替换为我需要的值。

除了如何添加变量和替换之外,我已经设法做所有事情。

所以我不需要帮助在管理员等中创建配置。

例如,用户在配置字段中输入以下内容:

<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>
4

1 回答 1

0

在您的“这里的东西”区域,您可以尝试:

 $codeSnippet = str_replace("{{amazing_value}}",$amazingValue,$codeSnippet);
于 2013-04-25T15:42:11.093 回答