在Magento中获取当前URL并显示一些内容 [英] Get Current URL in Magento and show something

查看:58
本文介绍了在Magento中获取当前URL并显示一些内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Magento中的当前URL并显示一些内容(如果我当前在该页面上).到目前为止,这就是我所做的并且有效.

I'm trying to get the current URL in Magento and show something if I'm currently on that page. So far, this is what I did and it worked.

 <?php
 $currentUrl = $this->helper('core/url')->getCurrentUrl();
 ?>     

 <?php if($currentUrl === 'http://powerplantv2.jehzlau.net/blog') { ?>I am in the blog page<?php } ?>

但是,我不想在源代码中对URL进行硬编码,因为如果转移到另一台服务器,则需要再次修改phtml文件.

However, I don't want to hard code the URL in the source code, because If I transfer to another server, I need to modify the phtml file again.

我尝试了所有在网上找到的内容,但没有成功.我希望这里的一些Magento专家可以启发我我做错了什么. :(

I tried everything that I found online, but it didn't work. I hope some Magento expert here can enlighted me of what I'm doing wrong. :(

推荐答案

您可以通过执行以下操作来检索当前的URL路径:

You can retrieve the current URL path by doing the following:

$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$path = $url->getPath();

然后使用一些基本逻辑,您可以定位/blog页面.

Then using some basic logic, you can target the /blog page.

$blogPaths = array('/blog', '/blog/', '/index.php/blog/');
if(in_array($path, $blogPaths))
{
    //Do something on /blog
}

这篇关于在Magento中获取当前URL并显示一些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆