What PHP code should be used to direct output of a plugin through a variable? That is, what should be done to enable ExpressionEngine code such as this:
{exp:my_plugin}
{my_plugin_variable1}
{my_plugin_variable2}
{/exp:my_plugin}
I stumbled upon this problem developing and using Browser Sniff plugin. In this plugin the code as this works
{exp:browser_sniff}
{if browser_name=="ie" AND browser_version<=6}
Some code
{/if}
{/exp:browser_sniff}
but the code as this
{exp:browser_sniff}
{browser_name}
{browser_version}
{/exp:browser_sniff}
does not. This code outputs variables {browser_name} and {browser_version} uninterpreted.
Docs section about plugin development does not seem to give an answer how to direct output of a plugin through variables. Also I did not find any plugin which uses variables. Certainly, there are such plugins, but I do not know which.
OK, after reading code of Reeposition plugin I figured out himself.
Here is PHP code which allows to direct the output of a plugin through a variables {my_variable1} and {my_variable2}:
$tagdata = str_replace('{my_variable1}', $var1, $tagdata);
$tagdata = str_replace('{my_variable2}', $var2, $tagdata);
$this->return_data = $tagdata;
And here is PHP code which allows both to direct the output of a plugin through a variables {my_variable1} and {my_variable2} and to make those variables available for use in conditionals:
$conds['my_variable1'] = $var1;
$conds['my_variable2'] = $var2;
$tagdata = str_replace('{my_variable1}', $conds['my_variable1'], $tagdata);
$tagdata = str_replace('{my_variable2}', $conds['my_variable2'], $tagdata);
$this->return_data = $FNS->prep_conditionals($tagdata, $conds);
It seems that this code is working correctly. Please, correct me if I am wrong at something.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.