0

How to get cms page FullActionName()

$request->getFullActionName() == 'cms_index_index'

Now,i want to get cms pages identifier name at that cms page

In Magento 1, I used this Mage::getSingleton('cms/page')->getIdentifier() it will get all so that i want know what to do into Magento 2 ?

6
  • you can get this type of action name in homepage Oct 25, 2016 at 17:10
  • I have a multiple page how i get dynamically? what means by this
    – Amit Bera
    Oct 25, 2016 at 17:11
  • No i want dynamically all in M1 i used this Mage::getSingleton('cms/page')->getIdentifier()
    – Magento 2
    Oct 25, 2016 at 17:12
  • @AmitBera in M1 i used this Mage::getSingleton('cms/page')->getIdentifier( it will get all so that i want know how to achive this in M2
    – Magento 2
    Oct 25, 2016 at 17:13
  • her is your answer which might help you : Click here Oct 26, 2016 at 11:07

3 Answers 3

0

you can set condition in your block,
Here my block php file contains :

protected $_request;

public function __construct(
    ...
    \Magento\Framework\App\Request\Http $request,
    ...
) {
    ...
    $this->_request = $request;
    ...
}


public function isHomepage()
{

    if ($this->_request->getFullActionName() == 'cms_index_index') {
        return true;
    }
    return false;
}
0

Full action name for CMS home is cms_page_view.

In order to get CMS page identifier , you need to inject

  • Cms model Magento\Cms\Model\Page

  • Magento\Store\Model\StoreManagerInterface

to __construct() then using those you get current page identifier

You want to identifier of cms page then you can get by below code:

/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* @var \Magento\Cms\Model\Page
*/
protected $_page;
 public function __construct(
...
\Magento\Cms\Model\Page $page,
\Magento\Store\Model\StoreManagerInterface $storeManager,
.....
    ) {
    ...
    $this->_page = $page;
    $this->_storeManager = $storeManager;
    ..

    }

public function getPageDetails(){
 $pageId = $request->getParam('page_id', $this->getRequest()->getParam('id', false));
 $this->_page->setStoreId($this->_storeManager->getStore()->getId());
   if ($this->_page->load($pageId)) {
    echo $this->_page->getIdentifier();
    }
}
8
  • No it's not working
    – Magento 2
    Oct 25, 2016 at 17:35
  • if($request->getFullActionName() == $this->getPageDetails()){ $t1 = $request->getFullActionName(); } i get in this way it's correct
    – Magento 2
    Oct 25, 2016 at 17:35
  • what? totally wrong code.. page identifier and full action name is different thing.
    – Amit Bera
    Oct 25, 2016 at 17:38
  • getFullActionName is content 3 sagement of page router name_Controllername_ActionName.
    – Amit Bera
    Oct 25, 2016 at 17:40
  • Hey my problem is in system configuration i get all cms page if i select home page i need to display on value so that how to i add condition
    – Magento 2
    Oct 25, 2016 at 17:42
0

In Magento 1.x you can get the page identifier by using getFullActionName() method.

But in Magento 2 if you want to fetch the Page Identifiers in the same way, you have to use multiple methods.

I generally use below method to get the Page identifiers as in format 'cms_index_index'.

<?php
$moduleName = $this->getRequest()->getModuleName();
$controllerName = $this->getRequest()->getControllerName();
$actionName = $this->getRequest()->getActionName();

# To get the Page Identifier as 'cms_index_index' format.
$pageIdentifier = $moduleName.'_'.$controllerName .'_'.$actionName;
echo $pageIdentifier;
?>

This will get all the pages Identifier in 'cms_index_index' format including your CMS and custom pages.

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.