3

我通过布局 xml 包含一个 js 文件:

例如:

<reference name="head">
    <action method="addItem">
        <type>js</type>
        <name>myjs.js</name>
    </action>
</reference>

这可以。但是,我在 myjs.js 中设置了一个 ajax 调用,并想从帮助类中提取帖子 url。

这怎么可能?

4

1 回答 1

8

在您对 I 的引用中,head我将添加一个块,该块将输出一个在添加的 myjs.js 文件之前设置 js var 的部分。

例如:

<reference name="head">
    <block type="page/html" name="mycustomblock" template="page/html/mycustomblock.phtml"/>
    <action method="addItem">
        <type>js</type>
        <name>myjs.js</name>
    </action>
</reference>

您的文件 mycustomblock.phtml 将包含:

<?php

// below is javascript that is being populated by your helper
?>
<script> var myblogpost = <?php echo Mage::helper('mycustom/helper')->blogPostUrl();?>; </script>
于 2012-08-04T20:36:44.160 回答