How do I detect what template is being used?
I need to detect that I am on the onestepcheckout page. I am currently using:
if ( $_SERVER['REQUEST_URI'] != "/onestepcheckout/"){
But I am wondering if I can 开发者_JAVA技巧get the info from a Magento object?
$currentUrl = $this->helper('core/url')->getCurrentUrl();
The method being called in Mage/Core/Helper/Url.php
/**
* Retrieve current url
*
* @return string
*/
public function getCurrentUrl()
{
$request = Mage::app()->getRequest();
$url = $request->getScheme() . '://' . $request->getHttpHost() . $request->getServer('REQUEST_URI');
return $url;
// return $this->_getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true));
}
Since the above may return a more full URL and not the URI you could use:
Mage::app()->getRequest()->getActionName();
and get the action name of the controller action being called.
You can check for the controller name in the IF condition.
if(Mage::app()->getRequest()->getControllerName() != 'onestepcheckout') {
Similarly, you can also get action name, module name, etc.
Have a look at this article:- Magento: How to get controller, module, action and router name?
Hope this helps. Thanks.
精彩评论