ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

entries tag parsed after plugin tag

January 14, 2012 3:17am

Subscribe [2]
  • #1 / Jan 14, 2012 3:17am

    barthoub

    63 posts

    Hi, I’m posting this question of Metalarend (an employee at my firm) here, because this (http://ellislab.com/forums/viewthread/206745/#962789) thread did not reach a point that satisfied us.

    Situation:

    {exp:channel:entries channel=“X”}
      {if ‘value’ != ‘{exp:ownplugin:action attr_1=”{channelX_tag}” attr_2=“key”}’}
      ok
      {/if}
    {/exp:channel:entries}

    Problem:
    When showing this template, the ownplugin is always giving back the wrong result. After some troubleshooting, the problem seems to be that it is trying to use the exact value “{channelX_tag}”, where I would expect it to first parse that tag, and replace the {channelX_tag} with a “real” value, then parse the plugin with that value, and then parse the complex if statement…

    When I use the ownplugin outside the if statement, all works well.
    When I put the {channelX_tag} somewhere else in the template, it gets parsed before the plugin, and thus then all works well too.
    But in the case above, it is just completely ignoring the {channelX_tag}.
    Parsing inward or outward is not working, as expected, as the only plugin is my own plugin. Could it be that it is ignoring everything from the plugin to parse, as it is a “{” inside some “’”?

    Could it be that the tag is embedded too deep? And is there a solution for that?
    Can I maybe use some code in my plugin constructor to check for possible redundand tags?

    I’m curious, and hoping that some of you may know a genious way to get out of this trouble!

  • #2 / Jan 16, 2012 1:29am

    John Henry Donovan

    12339 posts

    Hi bartblau,

    What version and build of EE are you using?

    What does your add-on do?

    Is is publicly available?

    Is the code above embedded in another template?

    If you use it outside the simple conditional does it work

    What is ‘value’ and what is {channelX_tag}?

    Can you explain in context what is trying to be achieved here? There may be simpler logic to use

  • #3 / Jan 19, 2012 7:59am

    barthoub

    63 posts

    <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.

  • #4 / Jan 27, 2012 7:07pm

    Kevin Smith

    4784 posts

    Hi bartblau and MetalArend,

    I’m afraid we’re not able to provide support for custom development work, but from looking at the Community Help thread linked in the first post, it looks like they did have some good suggestions there.

    Would you like me to move this thread over to Development and Programming, where you might have better luck with discussing the problem and potential solutions with other developers?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases