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

WordPress Trac noreply at wordpress.org
Tue Jan 31 13:07:11 UTC 2017

#21676: Pass a variable to get_template_part()
 Reporter:  sc0ttkclark      |       Owner:
     Type:  enhancement      |      Status:  reopened
 Priority:  normal           |   Milestone:
Component:  Template         |     Version:  3.4.1
 Severity:  normal           |  Resolution:
 Keywords:  has-patch close  |     Focuses:
Changes (by enrico.sorcinelli):

 * status:  closed => reopened
 * resolution:  maybelater =>


 I would to get back on track with this long awaited and requested

 I just updated the
 patch] for current trunk in my previous ticket  #36187 (even if was marked
 as duplicate).

 The patch affects not only `get_template_part()` but, other than
 `load_template()`, `locate_template()`, all `get_*` template family
 functions (I think that also it could be useful for example in
 `get_header()` ). Unit test has been also added.
 I used `$params` as scoped variable name.

 Even if there are workarounds for that, like use of globals, or
 `include(locate_template())` pattern and so on, the patch like that would
 really to clean up those approaches.

 In my opinion, abuse of globals is not too good practice and multiple
 times the people just need to repeat bits of data on partial content (for
 example loops which have considerable template HTML).

 Moreover they, like me of course, would like to reuse this template
 components across the site(s) in more than one place and or in different
 themes creating a sort of **templates codebase repository** (not plugins
 nor themes).

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

More information about the wp-trac mailing list