6

I want to encode an url with smarty.

 <a href="https://www.facebook.com/sharer/sharer.php?u={$var} " target="_blank"></a>

$var contains my datas url

3 Answers3

14

With escape modifier you may set optional escape_type 'url' to return rawurlencode().

{$var|escape:'url'}

By default {$var|escape} uses escape_type 'html' and returns htmlspecialchars() where '&' (ampersand) becomes &amp;. So 'url' might be useful. rawurlencode() protects literal characters from being interpreted as special URL delimiters:

<a href="https://www.facebook.com/sharer/sharer.php?u={$var|escape:'url'} " target="_blank"></a>
Andrey Volk
  • 3,513
  • 2
  • 17
  • 29
0

You can use the escape modifier

{$var|escape}

More info at: http://www.smarty.net/docsv2/en/language.modifier.escape.tpl

Tralli
  • 398
  • 1
  • 2
  • 12
0

You can also use PHP function urlencode as modifier.

PHP functions can be used as modifiers, $security permitting.

//the "rewind" paramater registers the current location
<a href="{$SCRIPT_NAME}?page=foo&rewind={$smarty.server.REQUEST_URI|urlencode}">click here</a>
Shoaib Iqbal
  • 1,208
  • 11
  • 21