|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
JasonDS Smarty Rookie
Joined: 25 Jan 2007 Posts: 25
|
Posted: Thu Jan 25, 2007 1:36 am Post subject: New Plugin: url_encode |
|
|
This wasn't so complicated to accomplish, but I find it useful
About: url_encode (PHP: urlencode(string)) encodes a string into standard URL format.
Usage: {$foo|url_encode}
File: ..\libs\plugins\modifier.url_encode.php
Contents:
Code: |
<?php
/**
* Smarty shared plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Function: smarty_url_encode
* Purpose: Encodes a string to be used in a url environment
* Example: "Jason, the maker of this script (Oh yea..), was here!" TO "Jason%2C+the+maker+of+this+script+%28Oh+yea..%29%2C+was+here%21"
* @author Jason Strese <Jason dot Strese at gmail dot com>
* @param string
* @return string
*/
function smarty_modifier_url_encode($string)
{
if( empty($string) )
{
return '#no_string_value_found';
}
else
{
return urlencode($string);
}
}
/* vim: set expandtab: */
?>
|
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Jan 25, 2007 2:34 am Post subject: |
|
|
FYI: you can use php functions as modifers under the default install. So:
{$foo|urlencode|default:'#no_string_value_found'}
Yours is a good shortcut if you use that a lot in your templates.
You may also find the distribution included escape modifier useful (it differs in that it uses rawurlencode() ) http://smarty.php.net/manual/en/language.modifier.escape.php
Cheers. |
|
Back to top |
|
JasonDS Smarty Rookie
Joined: 25 Jan 2007 Posts: 25
|
Posted: Thu Jan 25, 2007 5:52 am Post subject: |
|
|
Sorry, I didn't know you could do that..
I've only worked with Smarty for the past month and a half.
I have a lot of use for this small plugin, though it isn't a major thing, it does decrease a few lines here and there
Thanks for your suggestions |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|