Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

New Plugin: url_encode

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
JasonDS
Smarty Rookie


Joined: 25 Jan 2007
Posts: 25

PostPosted: Thu Jan 25, 2007 1:36 am    Post subject: New Plugin: url_encode Reply with quote

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
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jan 25, 2007 2:34 am    Post subject: Reply with quote

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
View user's profile Send private message
JasonDS
Smarty Rookie


Joined: 25 Jan 2007
Posts: 25

PostPosted: Thu Jan 25, 2007 5:52 am    Post subject: Reply with quote

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 Smile

Thanks for your suggestions Smile
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP