I’m developing a very small plugin for myself, and haven’t done this before, so I am sorry if this is a stupid question.
I am assigning a new global variable via the below code, and when using a print_r on the _global_vars array, I can see the variable assigned. However, when I try to output the variable inside of a template, nothing happens. Other variables will be replaced with their values, but the one I am assigning stays as just the variable name text. Is there some trick to making the variable output properly?
$this->EE->config->_global_vars = array_merge($this->EE->config->_global_vars, $site_data);Where $site_data is my array key/variable pair.
Basically I am using this as a learning exercise, it isn’t for a real project. I am trying to set a variable in the plugin and have it accessible in the template for testing purposes.
{if my_variable == 'value'}
execute logic
{if:else}
other logic
{/if}It is nothing complicated, I can accomplish what I want by enabling php in the template, but thought this would be a “safer” way to handle accessing a dynamic variable. A plugin may not be the best way to handle this, but I thought this would an extremely simple thing to accomplish and a plugin was the easiest addon to create. Perhaps another addon type would be better, I’m not sure. Any suggestions would be appreciated, I’ve been reading through the docs the last few days when I have spare time.
I would create a function in the plugin named for the variable then return the value which would appear as if it was a global var like this
{exp:my_plugin:my_var}
Replace my_plugin with your plugin name and my_var with the function name
Inside the plugin add the function
function my_var() { $val = “whateva”; return $val; }
Should work in theory
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.