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

WordPress Trac noreply at wordpress.org
Mon Aug 26 19:14:51 UTC 2013


#21676: Pass a variable to get_template_part()
-----------------------------+----------------------
 Reporter:  sc0ttkclark      |       Owner:
     Type:  enhancement      |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Template         |     Version:  3.4.1
 Severity:  normal           |  Resolution:  wontfix
 Keywords:  has-patch close  |
-----------------------------+----------------------

Comment (by caiocrcosta):

 I've been using my own get_template_part equivalent for nearly two years
 now, mainly because I need a controller function and to repeat the same
 HTML block (with variable data) accross the site. The function scope
 allows me to use any variable name I want to and to keep the PHP code
 inside the template file at a minimum.

 {{{
 function get_block( $file, $data = array() ) {
         $dir = trailingslashit( get_stylesheet_directory() );
         $blocks_dir = 'blocks/';
         $filepath = $dir . $blocks_dir . $file . '.php';

         if ( is_array( $data ) )
                 extract( $data );

         return include( $filepath );
 }
 }}}

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


More information about the wp-trac mailing list