Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Custom plugin help

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
JeffL
Smarty n00b


Joined: 29 Jun 2012
Posts: 2

PostPosted: Fri Jun 29, 2012 6:03 pm    Post subject: Custom plugin help Reply with quote

I believe what I have is just a compile time error,
but here it is..
I have created a smarty plugin that will load specified plug-ins from my API
Code:

<?php
$smarty->registerPlugin("function","runner", "add_runner");

function add_runner($params, $smarty)
{
    global $debug,$conf,$mysql,$smarty;
   
 
    $runner = $params["run"];
   
    $runinfo = parse_ini_file(CONFIGS . '/' . $params['run'] . '.conf.php', 1);
    $params['internal'] = '1';
    require(RUNNERS . '/WxWebAPI.php');
   
    $api = new WxWebAPI(&$debug,$params,&$conf,&$mysql,$smarty);
   
    $api->runner($params,$runinfo,$conf);   
         
 
 
}
?>

the file is named Template.php,
it is not in the smarty plugins dir
it is 'included' right after I set-up $smarty and all its fundamentals.

now here is the problem,
I am using a template called by my index.php ..
it has the needed info my api needs,
Code:

{runner run="metar" icao="khyx"}


in debug I can see the api being called like I expected,
the smarty debug template shows the variables are populated like expected..
but the actual template is filled with errors
Code:

Notice:  Undefined index: metarrel_humidity

(truncated for space)

So in a wild guess here.. the rest of the template must be getting parsed by Smarty
BEFORE the variables are set by the custom function
so how do I get Smarty to allow the variables to get set when it hits my custom function
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4592
Location: Hamburg / Germany

PostPosted: Sat Jun 30, 2012 4:05 pm    Post subject: Reply with quote

In Smarty3 the 2nd parameter is the template object. You must pass this to you object and use assign on the template object.

Code:
function add_runner($params, $template)
{
    global $debug,$conf,$mysql,$smarty;
   
 
    $runner = $params["run"];
   
    $runinfo = parse_ini_file(CONFIGS . '/' . $params['run'] . '.conf.php', 1);
    $params['internal'] = '1';
    require(RUNNERS . '/WxWebAPI.php');
   
    $api = new WxWebAPI(&$debug,$params,&$conf,&$mysql,$template);
   
    $api->runner($params,$runinfo,$conf);   
         
 
}

Back to top
View user's profile Send private message
JeffL
Smarty n00b


Joined: 29 Jun 2012
Posts: 2

PostPosted: Sat Jun 30, 2012 5:06 pm    Post subject: Reply with quote

Thanks
That did the trick !!

was going off this page in the docs
http://www.smarty.net/docs/en/api.register.plugin.tpl

and in action ..
The METAR report is using the new function
http://dev.michiganwxsystem.com/wxweb/wxweb.php
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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