我正在开发一个网站,该网站需要导航链接以平滑滚动到主页上的锚点,导航链接将链接到所有其他页面上的各个页面。我已经尝试了各种策略来实现这一目标无济于事。以下是我尝试过的一些方法。
网址使用.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}
检查是否有任何参数(逻辑上不起作为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}
我已经坚持了几个小时,并且在Google,SO和Smarty论坛上用尽了我的搜索查询。任何方向都将不胜感激。
答案 0 :(得分:0)
那么,当你的php文件是主页时,你能不能将变量传递给smarty?
$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>