I am preparing one common array which returns the complete details of all CMS pages. In this array, I need to pass the URL of all cms pages. I do have an identifier of all pages. How can I get the URL from it? Does anyone have an idea? Though it looks simple but bit tricky.

I have already used getPageUrl() function extending \Magento\Cms\Helper\Page helper class. But it simply adds the page identifier behind the store URL. Like for homepage, it returns same as for 404 page it returns

Here is the code snippet I have used:


namespace Sample\Core\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
     * @var \Magento\Cms\Helper\Page
    protected $cmsHelper;

    public function __construct(       
        \Magento\Cms\Helper\Page $cmsHelper       
    ) {        
        $this->cmsHelper = $cmsHelper;       

    public function getSeoData($cmsData)
        $url = $this->cmsHelper->getPageUrl($cmsData->getPageId());

Here is the screen-shot of backend configuration,

enter image description here

Is there any intelligent function available in Magento2 which automatically understand this return the correct URL of all cms pages?

Any help into this would be highly appreciated.


  • Can you please upload your code and cms page grid screenshots? – Rohan Hapani Sep 21 '18 at 7:14
  • @RohanHapani, Thanks for quick response. I have added code and screen-shot as you mentioned. Please see my updated question. Let me know if you have any query. – Pratik Navapara Sep 21 '18 at 7:43

Your Answer

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

Browse other questions tagged or ask your own question.