Skip to content

Instantly share code, notes, and snippets.

@xcommerce-gists
Created January 21, 2014 19:13
Show Gist options
  • Save xcommerce-gists/8546317 to your computer and use it in GitHub Desktop.
Save xcommerce-gists/8546317 to your computer and use it in GitHub Desktop.
Sample Magento block for an individual news article
<?php
/**
* News Item block
*
* @author Magento
*/
class Magentostudy_News_Block_Item extends Mage_Core_Block_Template
{
/**
* Current news item instance
*
* @var Magentostudy_News_Model_News
*/
protected $_item;
/**
* Return parameters for back url
*
* @param array $additionalParams
* @return array
*/
protected function _getBackUrlQueryParams($additionalParams = array())
{
return array_merge(array('p' => $this->getPage()), $additionalParams);
}
/**
* Return URL to the news list page
*
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/', array('_query' => $this->_getBackUrlQueryParams()));
}
/**
* Return URL for resized News Item image
*
* @param Magentostudy_News_Model_News $item
* @param integer $width
* @return string|false
*/
public function getImageUrl($item, $width)
{
return Mage::helper('magentostudy_news/image')->resize($item, $width);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment