1

I have created a custom module so that I can call a block from a cms page.

{{block type="wpsync/getpostcontent" template="wpsync/getpostcontent.phtml" wpurl="http://localhost/about"}}

I am getting

exception 'Mage_Core_Exception' with message 'Invalid block type:

Can't see what I am doing wrong.

local/Elevated/Wpsync/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Elevated_Wpsync>
            <version>1.0</version>
        </Elevated_Wpsync>
    </modules>
    <global>
        <blocks>
            <getpostcontent>
                <class>Elevated_Wpsync_Block</class>
            </getpostcontent>
        </blocks>
        <models>
            <getpostcontent>
                <class>Elevated_Wpsync_Model</class>
            </getpostcontent>
        </models>
    </global>
</config>

local/Elevated/Wpsync/Block/Getpostcontent.php

<?php
class Elevated_Wpsync_Block_Getpostcontent extends Mage_Core_Block_Template {
    public function getPostContentFromUrl() {

        $url = $this->getData('wpurl');
        // call model to fetch data
        $pagecontent = Mage::getModel("wpsync/getpostcontent")->getPostContentFromUrl($url);

        return $pagecontent;
    }
}

local/Elevated/Wpsync/Model/Getpostcontent.php

<?php

class Elevated_Wpsync_Model_Getpostcontent extends Mage_Core_Model_Abstract {
    public function getPostContentFromUrl($url) {
        return "hello";
    }
}

app/etc/modules/Elevated_Wpsync.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Elevated_Wpsync>
            <active>true</active>
            <codePool>local</codePool>
        </Elevated_Wpsync>
    </modules>
</config>

app/design/frontend/default/default/template/wpsync/getpostcontent.phtml

<?php
    echo $this->getPostContentFromUrl();

2 Answers 2

0

Please change your config.xml to:

<?xml version="1.0"?>
<config>
    <modules>
        <Elevated_Wpsync>
            <version>1.0</version>
        </Elevated_Wpsync>
    </modules>
    <global>
        <blocks>
            <wpsync>
                <class>Elevated_Wpsync_Block</class>
            </wpsync>
        </blocks>
        <models>
            <wpsync>
                <class>Elevated_Wpsync_Model</class>
            </wpsync>
        </models>
    </global>
</config>
1
  • Thanks michael. I had done that last night after I noticed my mistake.
    – T. Brown
    Commented May 29, 2016 at 15:39
0

As an alternative to Michael's solution you can also replace:

{{block type="wpsync/getpostcontent" template="wpsync/getpostcontent.phtml" wpurl="http://localhost/about"}}

With

{{block type="getpostcontent/getpostcontent" template="wpsync/getpostcontent.phtml" wpurl="http://localhost/about"}}

Notice the change in the block type. The first part of the block type is defined by this in your config.xml

<blocks>
    <getpostcontent>
        <class>Elevated_Wpsync_Block</class>
    </getpostcontent>
</blocks>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.