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

M1 i used this Mage::getSingleton('cms/page')->getIdentifier() it will get all so that i want know how to achieve this in M2

  • you can get this type of action name in homepage – Rakesh Jesadiya Oct 25 '16 at 17:10
  • I have a multiple page how i get dynamically? what means by this – Amit Bera Oct 25 '16 at 17:11
  • No i want dynamically all in M1 i used this Mage::getSingleton('cms/page')->getIdentifier() – Magento 2 Oct 25 '16 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 '16 at 17:13
  • her is your answer which might help you : Click here – Ronak Chauhan Oct 26 '16 at 11:07
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();
    }
}
  • No it's not working – Magento 2 Oct 25 '16 at 17:35
  • if($request->getFullActionName() == $this->getPageDetails()){ $t1 = $request->getFullActionName(); } i get in this way it's correct – Magento 2 Oct 25 '16 at 17:35
  • what? totally wrong code.. page identifier and full action name is different thing. – Amit Bera Oct 25 '16 at 17:38
  • getFullActionName is content 3 sagement of page router name_Controllername_ActionName. – Amit Bera Oct 25 '16 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 '16 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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