|
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 |
JeffL Smarty n00b
Joined: 29 Jun 2012 Posts: 2
|
Posted: Fri Jun 29, 2012 6:03 pm Post subject: Custom plugin help |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jun 30, 2012 4:05 pm Post subject: |
|
|
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 |
|
JeffL Smarty n00b
Joined: 29 Jun 2012 Posts: 2
|
|
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
|