3 magento
我通过布局xml包含一个js文件:
例如:
<reference name="head">
<action method="addItem">
<type>js</type>
<name>myjs.js</name>
</action>
</reference>
Run Code Online (Sandbox Code Playgroud)
这可以.但是,我在myjs.js中设置一个ajax调用,并希望从帮助类中提取post url.
这怎么可能?
在你对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>
Run Code Online (Sandbox Code Playgroud)
你的文件mycustomblock.phtml将包含:
<?php
// below is javascript that is being populated by your helper
?>
<script> var myblogpost = <?php echo Mage::helper('mycustom/helper')->blogPostUrl();?>; </script>
Run Code Online (Sandbox Code Playgroud)