[wp-trac] [WordPress Trac] #21676: Pass a variable to get_template_part()

WordPress Trac wp-trac at lists.automattic.com
Fri Sep 14 18:39:30 UTC 2012


#21676: Pass a variable to get_template_part()
-------------------------------------+-----------------------------
 Reporter:  sc0ttkclark              |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  Template                 |     Version:  3.4.1
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |
-------------------------------------+-----------------------------

Comment (by wonderboymusic):

 Want a dirty workaround?

 {{{
 function get_template_part_data() {
         $func = wp_list_filter( debug_backtrace(), array( 'function' =>
 'get_template_part' ) );
         if ( $func )
                 return $func[key($func)]['args'][2];
 }

 $data = array( 'foo' => 'bar' );
 get_template_part( 'content', 'whatever', $data );


 exit();
 }}}

 And then in content-whatever.php:

 {{{
 print_r( get_template_part_data() );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21676#comment:11>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list