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.

Plugin array parsed with nested duplicate key names

September 05, 2014 9:10pm

Subscribe [1]
  • #1 / Sep 05, 2014 9:10pm

    jonleecraw

    6 posts

    EE 2.9
    PHP 5.5

    Is there a way to distinguish between shared key names in a nested template loop? Example:

    plugin function:

    class Test_pi{
     public function testloop(){
      
      $inside_arr = array(
        'inside' => 'Inside!',
        'shared' => 'Shared Inside!'
        );
      $inside = array($inside_arr);
      
      $outside_arr = array(
       'outside' => 'Outside!',
       'shared' => 'Shared Outside!',
       'inarray' => $inside
       );
    
      $return_arr = array($outside_arr);
    
      return ee()->TMPL->parse_variables(ee()->TMPL->tagdata, $return_arr);
     }
    }

    template view:

    {exp:test_pi:testloop}
      {outside} {shared}
        
    
        {inarray}
          {inside} {shared}
        {/inarray}
        
    
    {/exp:test_pi:testloop}

    The desired output is

    Outside! Shared Outside! 
    Inside! Shared Inside!

    but the actual result is

    Outside! Shared Outside! 
    Inside! Shared Outside!

    so as you can see, the shared template variable name is not namespace respected, and I haven’t found a way to access the inside loop’s {shared} variable. I’ve tried stackoverflow and the EE docs on the template engine, but haven’t found anything. Anyone aware of a way to handle this, besides some third party product?

     

     

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

ExpressionEngine News!

#eecms, #events, #releases