We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to direct output of a plugin through a variable?

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
17 years ago
Laisvunas's avatar Laisvunas

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.

       
Laisvunas's avatar
Laisvunas
879 posts
17 years ago
Laisvunas's avatar Laisvunas

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.