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

WordPress Trac noreply at wordpress.org
Fri Sep 16 15:29:20 UTC 2016


#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:  maybelater
 Keywords:  has-patch close  |     Focuses:
-----------------------------+-------------------------

Comment (by sayedwp):

 Well, meanwhile, this can be used which will do the same thing

 {{{

 /**
  * Load a template part into a template
  *
  * @param string $slug The slug name for the generic template.
  * @param string $name The name of the specialised template.
  * @param array $params Any extra params to be passed to the template
 part.
  */
 function get_template_part_extended( $slug, $name = null, $params =
 array() ) {
         if ( ! empty( $params ) ) {
                 foreach ( (array) $params as $key => $param ) {
                         set_query_var( $key, $param );
                 }
         }
         get_template_part( $slug, $name );
 }

 }}}

 I use this in my projects sometimes, it makes extra params available in
 the template part.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21676#comment:56>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list