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')
?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With