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

WordPress Trac noreply at wordpress.org
Mon Apr 30 12:48:21 UTC 2018


#21676: Pass a variable to get_template_part()
-------------------------------------------+------------------------------
 Reporter:  sc0ttkclark                    |       Owner:  SergeyBiryukov
     Type:  enhancement                    |      Status:  reviewing
 Priority:  normal                         |   Milestone:  Awaiting Review
Component:  Template                       |     Version:  3.4.1
 Severity:  normal                         |  Resolution:
 Keywords:  has-patch close needs-testing  |     Focuses:
-------------------------------------------+------------------------------

Comment (by enrico.sorcinelli):

 Hi @mboynes did you take a look on the latest
 [https://core.trac.wordpress.org/attachment/ticket/21676/21676.10.patch
 patch]?
 It doesn't uses `extract()` nor introduces globals at all, but allows to
 pass variables scoped to template files, for example:

 {{{
 <?php
 get_template_part( 'parts/template', '', array( 'foo' => 'baz' ) );
 }}}

 and in ''parts/template.php'':

 {{{
 <?php
 echo $params['foo'];
 }}}

 or:

 {{{
 <?php
 get_header( 'header', '', array( 'foo' => 'baz') );
 }}}

 and so on.

 The `$params` scoped variable name can be replaced with a more specific
 name, for example `$wp_tmpl_args`.

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


More information about the wp-trac mailing list