问题
I'm attempting to call a phtml file from Ajax on the homepage of my Magento site. I basically created a copy of app/design/frontend/base/default/template/catalog/product/list.phtml and customized it to view a particular category. If I add a block pointing to this file in the CMS section, I can view it just fine. However, I want to call this file via Ajax.
I followed the instructions to create a module here, and then I attempted to follow the logic of Ajax in Magento by following this post. However, in the last step it lists:
<module_controller_action>
<block type="module/block" name="root" output="toHtml" template="module/template.phtml"/>
</module_controller_action>
Where do I insert this? Also, for the template="module/template.phtml", what folder is that referring to?
回答1:
That bit of XML needs to be put in a layout XML file, which is found in the
app/design/frontend/base/default/layout/
directory. You can update any of the layout files with that snippit, but I don't recommend that. I usually recommend creating a local.xml file in your template's layout directory
app/design/frontend/*/*/layout/local.xml
Now, make sure you update the xml snippit too so that it says your real module, controller, and action name! :)
The template="module/template.phtml" will also need to be customized to reflect the path to the phtml file. So if you put your custom phtml file in
app/design/frontend/*/*/template/myfolder/myphtml.phtml
, then the code would be template="myfolder/myphtml.phtml"
来源:https://stackoverflow.com/questions/5081844/magento-call-template-phtml-file-via-ajax