2016-07-21 55 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>