我在我的网站上有一个博客页面,它使用Smarty创建帖子,我想使用它向他们添加一个WhatsApp共享按钮。我已经在整个互联网上搜索过了,我发现了这个:
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}我现在正尝试在我的blog.tpl文件中使用这个:
<a class="whatsapp" href="whatsapp://send?text={$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}">Compartilhar</a>我的代码出了什么问题,我怎样才能修复它呢?
发布于 2016-10-15 18:37:14
由于以下几个原因,您的代码无法工作:
stackoverflow/questions/40062450/...。URL以协议(通常是http://)开始。您发送的文本应该是:
URI}&)。当您希望将&用作URL中的参数时,未能正确编码它将导致生成与您想象不同的URL。Smarty为此提供了escape变量修饰符。escape修饰符也在这里帮助您。综合起来,最好的方法是将URL构建到单独的智能variable中,然后将其写入href属性中:
{!--
* Generate the URL we want to send using WhatsApp
* and store it in the $url Smarty variable
* There is no encoding here
* --}
{capture assign=url}{strip}
http://{$smary.server.HTTP_HOST}{$smarty.server.REQUEST_URI}
{/strip}{/capture}
{!--
* The URL to invoke the WhatsApp app (and ask it to send $url as message) is:
* whatsapp://send?text={$url|escape:url}
* --}
{!--
* Generate correct HTML that contains the correct whatsapp URL
* that contains as parameter the URL generated in $url
* --}
<a class="whatsapp" href="whatsapp://send?text={$url|escape:url|escape:html}">Compartilhar</a>https://stackoverflow.com/questions/40062450
复制相似问题