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

WordPress Trac wp-trac at lists.automattic.com
Thu Aug 23 20:15:37 UTC 2012


#21676: Pass a variable to get_template_part()
-----------------------------+-----------------------------
 Reporter:  sc0ttkclark      |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Template         |    Version:  3.4.1
 Severity:  normal           |   Keywords:
-----------------------------+-----------------------------
 Having the ability to pass a variable into get_template_part would be
 invaluable, it would really clean up the issues with using globals and to
 further cement it's use rather than the alternative of a normal PHP
 include/require.

 It would be the third variable passed into get_template_part, which I
 could pass it a string, array, object, or whatever I want really. Here's
 an example of passing all the current scope's variables:

 {{{
 <?php get_template_part( 'twitter', 'feed', compact( array_keys(
 get_defined_vars() ) ) ); ?>
 }}}

 and then catching them in my feed-twitter.php file:

 {{{
 if ( !empty( $_data ) && is_array( $_data ) )
         extract( $_data, EXTR_SKIP );
 }}}

 I can pass other things in, but that's a really valuable example in my
 uses for this new variable.

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


More information about the wp-trac mailing list