2016-07-21 53 views
0

我正在一个网站上工作,需要导航链接平滑滚动到主页上的锚点,导航链接链接到所有其他页面上的单独页面。我尝试了各种各样的策略来达到这一目的无济于事。以下是我尝试过的一些方法。Smarty设置基于URL的导航href

网址使用.htaccess构建。 Home没有请求URI,因为它是网站的索引页面。 PUBLIC_URL在配置文件中设置。

检查HTTP_HOST是否等于PUBLIC_URL,并且没有参数正在传递给其他页面。

{if $smarty.server.HTTP_HOST == $smarty.const.PUBLIC_URL && $smarty.server.REQUEST_URI == ''} 
<a href="#locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{else} 
<a href="{$public_url}locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{/if} 

检查,如果有任何PARAMS(逻辑上不作为PUBLIC_URL工作是一个常数,因此将始终返回false在这种情况下)。

{if $smarty.const.PUBLIC_URL == ''} 
<a href="#locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{else} 
<a href="{$public_url}locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{/if} 

外出时关闭以正在处理的模板(逻辑上的资产净值包含在它自己的模板文件不工作)的。

{if $smarty.template == 'home.tpl'} 
<a href="#locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{else} 
<a href="{$public_url}locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{/if} 

查看是否不存在请求URI。仍然返回false。

{if $smarty.server.REQUEST_URI === ''} 
<a href="#locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{else} 
<a href="{$public_url}locations">Our Locations <i class="ti-angle-down"></i></a></span> 
{/if} 

我一直停留在此的几个小时,并已用尽谷歌上搜索我的询问,SO,和Smarty的论坛。任何方向将不胜感激。

回答

0

那么,你不能只是通过一个变量来smarty在你的PHP文件时,它的主页?

$smarty->assign('this_is_the_home_page',true); 

,然后在模板

{if $this_is_the_home_page} 
{$url="#locations"} 
{else} 
{$url=$public_url|cat:'locations'} 
{/if} 

<a href="{$url}">Our Locations <i class="ti-angle-down"></i></a></span>