Reputation:
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
Upvotes: 7
Views: 22830
Reputation: 1178
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>
Upvotes: 0
Reputation: 3549
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 &
. 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>
Upvotes: 15
Reputation: 408
You can use the escape modifier
{$var|escape}
More info at: http://www.smarty.net/docsv2/en/language.modifier.escape.tpl
Upvotes: 0