Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get particular page URL in magento

Tags:

I would like to get a page's URL key in Magento.

For example, I have a CMS page called "What's New" with the identifier (or URL key) "whats_new". Its correct URL is therefore http://mysite.com/whats_new

Currently I use this code to echo its location:

<?php echo Mage::getBaseUrl();?>whats_new 

I feel it's bad practice because its identifier (or URL key) is administrable; if its URL key or identifier changes then the link will break. What is the proper way to echo its dynamic URL key? Perhaps something similar to Wordpress's get_permalink('10')?

like image 628
Gowri Avatar asked Sep 15 '11 12:09

Gowri


People also ask

How do I get parameters in Magento 2?

You can get Post Data value in the After plugin using Magento 2. You can get all the Params() data after the plugin which is sent by request. If you send the query string Or data within the URL, you can get those data using getParams() in the after plugin.


2 Answers

I think this will do what you want:

<?php echo Mage::helper('cms/page')->getPageUrl( $pageId ) ?> 

Replace $pageId with the correct id for the page you are linking to and it should work.

like image 142
Josh Avatar answered Sep 20 '22 15:09

Josh


Try this

<?php echo $this->getUrl('whats_new');?> 

If you need to add url key dynamically then

<?php echo $this->getUrl($yourDynamicVariable);?> 

of course you must implement the features that you need to fill the variable if url key is changed

like image 42
Anton S Avatar answered Sep 22 '22 15:09

Anton S