Magento:从 Ajax 调用模板时呈现空白页面

发布于 2024-10-18 20:57:42 字数 2105 浏览 1 评论 0原文

首先,我必须为我对这个问题缺乏了解而道歉。我对 Magento 还很陌生,根据我遇到的信息,我应该能够让它工作。我从这里开始。我能够使用 Ajax 方法进行调用,但我得到一个空白的 2column-left.phtml 作为我的输出(因此我看到标题、左列、空白主列和页脚)。我的文件设置如下:

app/local/MyModule/Featured/Block/Featured.php

<?php  
class MyModule_Featured_Block_Featured extends Mage_Core_Block_Template  
{  
    public function __construct()  
    {  
        $this->_controller = 'featured';  
        $this->_blockGroup = 'featured';  
        parent::__construct();  
    }  
}  
?>

app/local/MyModule/Featured/controllers/FeaturedController.php

<?php 
class MyModule_Featured_FeaturedController extends Mage_Core_Controller_Front_Action
{
    public function displayAction()
    {
        $this->loadLayout()->renderLayout();
    }
}
?> 

app/local/MyModule/Featured/etc/config.xml

<config>
    <modules>
        <MyModule_Featured>
            <version>0.1.0</version>
        </MyModule_Featured>
    </modules>
    <frontend>
        <routers>
            <featured>
                <use>standard</use>
                <args>
                    <module>MyModule_Featured</module>
                    <frontName>featured</frontName>
                </args>
            </featured>
        </routers>
    </frontend>
</config>

app/ design/frontend/default/myLayout/layout/local.xml

<config>
    <featured_featured_display>
        <block type="module/block" name="root" output="toHtml" template="catalog/product/featured.phtml" />
    </featured_featured_display>
</config>

主页自定义 phtml 上的 Ajax 代码:

var url = "<?php echo $this->getUrl('featured/featured/display') ;?>";
jQuery(document).ready(function() {
    jQuery('#featured-products').load(url);
});

First off, I must apologize for my lack of knowledge on the subject. I'm still new to Magento, and with the information I've come across, I should've been able to get this working. I started off here. I'm able to get the Ajax method to make a call, but I'm getting a blank 2column-left.phtml as my output (So I'm seeing the header, left column, blank main column, and footer). I have my files set up as so:

app/local/MyModule/Featured/Block/Featured.php

<?php  
class MyModule_Featured_Block_Featured extends Mage_Core_Block_Template  
{  
    public function __construct()  
    {  
        $this->_controller = 'featured';  
        $this->_blockGroup = 'featured';  
        parent::__construct();  
    }  
}  
?>

app/local/MyModule/Featured/controllers/FeaturedController.php

<?php 
class MyModule_Featured_FeaturedController extends Mage_Core_Controller_Front_Action
{
    public function displayAction()
    {
        $this->loadLayout()->renderLayout();
    }
}
?> 

app/local/MyModule/Featured/etc/config.xml

<config>
    <modules>
        <MyModule_Featured>
            <version>0.1.0</version>
        </MyModule_Featured>
    </modules>
    <frontend>
        <routers>
            <featured>
                <use>standard</use>
                <args>
                    <module>MyModule_Featured</module>
                    <frontName>featured</frontName>
                </args>
            </featured>
        </routers>
    </frontend>
</config>

app/design/frontend/default/myLayout/layout/local.xml

<config>
    <featured_featured_display>
        <block type="module/block" name="root" output="toHtml" template="catalog/product/featured.phtml" />
    </featured_featured_display>
</config>

Ajax Code on Homepage custom phtml:

var url = "<?php echo $this->getUrl('featured/featured/display') ;?>";
jQuery(document).ready(function() {
    jQuery('#featured-products').load(url);
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一百个冬季 2024-10-25 20:57:42

我相信布局文件的根节点应该是 而不是

<子>PS
如果您不想使用 jQuery - 以避免膨胀 - Magento 已经将 Prototype 作为标准,并且可以执行完全相同的操作。< /子>

var url = "<?php echo $this->getUrl('featured/featured/display') ?>";
document.observer('dom:loaded', function(){
    new Ajax.Updater('featured-products', url);
});

I believe the layout file's root node should be <layout> and not <config>.

P.S.
If you wanted to do without jQuery - to avoid bloat - Magento already has Prototype as standard and can do exactly the same.

var url = "<?php echo $this->getUrl('featured/featured/display') ?>";
document.observer('dom:loaded', function(){
    new Ajax.Updater('featured-products', url);
});

留蓝 2024-10-25 20:57:42

加载布局通常包含默认句柄,所以我的猜测是您的分配没有效果,因为已经加载了根音符。尝试先删除根节点,然后将其添加回您的唯一节点。

Load layout includes the default handle normally, so my guess is that your assignment has no effect because there is a root note being loaded already. Try removing the root node first, and then add it back as your only node.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文