<MetalArend, posting on the bartblau account>
I created a simple plugin and a test-case, to make it easy to recreate the problem.
The plugin “exa/pi.exa.php”:
### ### ###
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! defined('EXA_NAME'))
{
define('EXA_NAME', 'ChannelField');
define('EXA_VERSION', '0.1.20111214');
define('EXA_AUTHOR', 'Bart Reunes');
define('EXA_AUTHOR_URL', 'twitter.com/MetalArend');
define('EXA_DESCRIPTION', 'Example');
}
$config['name'] = EXA_NAME;
$config['version'] = EXA_VERSION;
$plugin_info = array(
'pi_name' => EXA_NAME,
'pi_version' => EXA_VERSION,
'pi_author' => EXA_AUTHOR,
'pi_author_url' => EXA_AUTHOR_URL,
'pi_description' => EXA_DESCRIPTION,
'pi_usage' => Exa::usage()
);
class Exa
{
public function __construct ()
{
$this->EE =& get_instance();
$this->return_data = $this->test();
}
public function test ()
{
$key = $this->EE->TMPL->fetch_param( 'key', FALSE );
if ( FALSE === $key ) { return 'key not found'; }
if ( 1 === preg_match( '/[\{\}]+/', $key ) )
{
return 'not parsed';
}
else
{
return 'parsed';
}
}
public function usage ()
{
ob_start();
?>
No documentation yet.
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}
### ### ###
The template:
### ### ###
{exp:exa:test} === key not found
{exp:exa:test key="key"} === parsed
{exp:exa:test key="{key}"} === not parsed
{if "parsed" == "{exp:exa:test key="key"}"}
parsed
{/if} === parsed
{exp:channel:entries limit="1"}
{exp:exa:test key="{title}"}
{/exp:channel:entries} === parsed
{exp:channel:entries limit="1"}
{if "not parsed" == "{exp:exa:test key="{title}"}"}
not parsed
{/if}
{/exp:channel:entries} === not parsed
### ### ###
The problem is in the last example: one would expect the {title} tag to get parsed, before calling the plugin, as is the case in the second-last example. Instead the parser seems to simply ignore the tag, and therefor the plugin gets not a value, but the string “{title}”.
What version and build of EE are you using?
v2.3.1 - Build: date 20111017
What does your add-on do?
In the first example it is returning the sum of the two attributes, in the second example it is returning if there is still a “{" or "}” inside the key value.
Is is publicly available?
It was an example, as is the example I’m providing with this post, only to try to explain where things go wrong.
Is the code above embedded in another template?
No, it isn’t.
If you use it outside the simple conditional does it work?
As the example in this post shows: yes, it is.
What is ‘value’ and what is {channelX_tag}?
Value is whatever value one would not hope for to get back from the plugin, channelX_tag is a value I can only get (easily) from inside the channel:entries tags.
Can you explain in context what is trying to be achieved here? There may be simpler logic to use
There certainly is a simpler logic - for example one could include the result value inside the plugin, and make the plugin itself an if-tag (so-to-speak). But then the problem still exists, and one still has to wonder why it wasn’t working in the first place.
Hopefully someone can point me to a logical solution, or simply a reason “why” it is just plain wrong what I’m trying to achieve here. The actual problem I got with the original plugin, ánd the second plugin, got resolved through some dirty work-around, but if we could do something about the core of the problem, it would make ExpressionEngine even better.