【问题标题】:Is it possible to use js in magento block?是否可以在 magento 块中使用 js?
【发布时间】:2015-12-29 13:38:09
【问题描述】:

我在我的静态块中使用了{{block type="core/template" template="page/html/FILE_NAME.phtml"}},并想在主页中使用。 在此之前,我在我的主页和我写的主页的“设计”部分使用了该块

<reference name="block_name">
<action method="addJs">
<script>js_name</script>
</action>
</reference>

但它不起作用。谁能帮帮我?....

【问题讨论】:

  • 如果你想在block之前使用js,为什么不在你上面​​写FILE_NAME.phtml

标签: javascript magento static block


【解决方案1】:

如果您仅在主页中使用该特定块,您可以在主页layout handle 下使用head 引用添加。是这样的。。

<cms_index_index>
   <reference name="head">
      <action method="addJs"><script>js_name</script></action>
   </reference>
</cms_index_index>

【讨论】:

  • 我已经在我的 local.xml 以及主页布局更新 xml 部分中使用了它......但是我想在上面使用 js 的块......仍然没有显示它的工作......是它是正确的方式吗?还是你想让我做别的?...
  • 而不是特定于块,我们确实加载特定布局句柄的头部部分。这也将确保我们在其他内容之前加载该内容。在我的情况下,如果在主页上使用这个块,我会像上面那样加载,或者如果我有更少的脚本部分,我会在块的相同 phtml 文件上编写(例如,某些轮播激活特定)。
  • 我想在某些元素上使用的 js 如果我在 .phtml 文件中使用没问题,但对于使用静态块它不起作用....
【解决方案2】:

将以下行添加到您的主页设计部分

<default>
    <reference name="head">
        <block type="core/template" name="custom_js" as="custom_js" template="custom/js.phtml" />
    </reference>
</default>

app/design/frontend/{interface}/{theme}/template/custom/js.phtml 中添加:

<script type="text/javascript">
   //your js here
</script>

【讨论】:

    【解决方案3】:

    我已经解决了这个问题,只是从静态块(将由管理员给出)和其他东西,如我在 .phtml 页面中定义的 js 和 div ......及其作品。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-16
      • 2017-07-19
      • 2022-06-19
      • 2021-11-04
      • 2012-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多