Following on from this question, I'm now trying to rework the plugin so that I can do:
{exp:deetector}
{user_agent}
{hash}
{/exp:deetector}
but with the code below, I get no output:
public function __construct()
{
$this->EE =& get_instance();
include(PATH_THIRD.'/deetector/libraries/detector.php');
$this->ua = $ua;
$tagdata = $this->EE->TMPL->tagdata;
$variables[] = array(
'user_agent' => $this->ua->ua,
'hash' => $this->ua->uaHash,
'browser_os' => $this->ua->full,
'browser' => $this->ua->browser,
'browser_full' => $this->ua->browserFull
);
return $this->EE->TMPL->parse_variables($tagdata, $variables);
}
If I do $this->return_data = $this->ua->xx
for each of the variables listed above I get output, but not if I parse the $variables array.
I've also tried $variables = array
but get Undefined offset: 0.
If you're just using the constructor for output, make sure the plugin class has a public property return_data
which contains the parsed tagdata:
$this->return_data = $this->EE->TMPL->parse_variables($tagdata, $variables);
For any other method in the class, you can just simply return the parsed data, as per your example.
As a sidenote, I take it you're not looping any data here. Consider using the parse_variables_row
method instead, so extra variables like count
, total_results
and switch
are omitted. Using that method doesn't require a nested array, so it would come down to this:
$variables = array(
'user_agent' => $this->ua->ua,
...
);
$this->return_data = $this->EE->TMPL->parse_variables_row($tagdata, $variables);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With