Skip to main content
Commonmark migration
Source Link

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/
Source Link

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answermy answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
added working code.
Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

This is because you are not using the right block class in this case. I am sure about this, because I know you are using Mage_Core_Block_Template block if you have followed my answer in your previous thread.

Let us look what is gone wrong here. The error says you are calling getImageUrl() on a non-object. This means $_category is a non-object. Now as per your template code, $_category is defined like this.

$_category  = $this->getCurrentCategory();

This means you are expecting $_category should hold the current category. But what really happened is it holds a NULL value since $this->getCurrentCategory() returns nothing. A quick solution for this is,

$_category = Mage::registry('current_category');
if ($_category) {
    //then show your banner code.
} else {
    //do nothing
}

Most of the case, it will work. If you template is more complex than this, then you may need to create a custom block for showing banner and then use that block instead of Mage_Core_Block_Template block.

Let me know your feedback after try this.

#EDIT

I tested below code and it works well for me.

<?php
$_helper    = $this->helper('catalog/output');
$_category  = Mage::registry('current_category');
$_imgHtml   = '';
if ($_imgUrl = $_category->getImageUrl()) {
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->escapeHtml($_category->getName()).'" title="'.$this->escapeHtml($_category->getName()).'" /></p>';
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>

<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
corrected mis-spelling in the previous edit :)
Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103
Loading
corrected spelling
Source Link
Qaisar Satti
  • 32.5k
  • 18
  • 87
  • 137
Loading
Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103
Loading