Part of the EllisLab Network
   
 
Some useful plugins for Smarty
Posted: 29 December 2006 04:53 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  8
Joined  12-08-2006

Today I wrote some very small plugins for Smarty, which allow me to use CI’s URL helper functions (base_url() and site_url()) directly from my Smarty templates.

So I decided to share them:
function.site_url.php

<?php
function smarty_function_site_url($params,&$smarty)
{
    
//check if the needed function exists
    //otherwise try to load it
    
if (!function_exists('site_url')) {
        
//return error message in case we can't get CI instance
        
if (!function_exists('get_instance')) return "Can't get CI instance";
        
$CI= &get_instance();
        
$CI->load->helper('url');
    
}
    
if (!isset($params['url'])) return base_url();
    else return
site_url($params['url']);
}
?>

function.base_url.php

<?php
function smarty_function_base_url($params,&$smarty) {
    
if (!function_exists('base_url')) {
        
//return error message in case we can't get CI instance
        
if (!function_exists('get_instance')) return "Can't get CI instance";
        
$CI= &get_instance();
        
$CI->load->helper('url');
    
}
    
    
return base_url();
    
}
?>


Installation: just drop these two files in smarty’s plugin folder.
Usage:
{base_url} to output the root url of your site (e.g. http://fest.servehttp.com/)
{site_url url=“controller/function”} produces something like this http://fest.servehttp.com/index.php/controller/function


Not the most advanced plugins ever, but some might find them useful.

 Signature 

Signature for rent. Good as new.
3 lines/80 chars max.
$0.02 per post

Profile
 
 
Posted: 10 January 2007 04:50 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  254
Joined  10-04-2006

Thanks a lot fest.
I use everytime Smarty. I am not really fond of smarty plugins but yours cuold be useful !

Could you write it in wiki in a smarty section ?

See you

 Signature 

Sylvain Gourvil
PHP Developer
French scuba divingMotivation and team building

Profile
 
 
Posted: 10 January 2007 10:19 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  8
Joined  12-08-2006

No problem: http://www.codeigniter.com/wiki/Use_URL_helper_from_Smarty/

 Signature 

Signature for rent. Good as new.
3 lines/80 chars max.
$0.02 per post

Profile
 
 
Posted: 10 January 2007 10:51 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  254
Joined  10-04-2006

Nice job !
Thx

 Signature 

Sylvain Gourvil
PHP Developer
French scuba divingMotivation and team building

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66426 Total Logged-in Users: 37
Total Topics: 84790 Total Anonymous Users: 3
Total Replies: 455006 Total Guests: 234
Total Posts: 539796    
Members ( View Memberlist )
Newest Members:  llogocsaturkeytherendStudioGeorgiaJZeerfedegheEdgedcenticeRoger_Mxcamilo