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

WordPress Trac noreply at wordpress.org
Fri Jul 3 00:07:55 UTC 2020


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

Comment (by enrico.sorcinelli):

 Before the patch, the only way to see `$args` inside the template is to
 add `global $args` inside template.
 After the patch and with `global` statement, you still continue to have
 access to original `$args`, not to the empty array nor the third argument
 of `get_template_part()`.

 To be honest, in all other cases where template doesn't use `global
 $args`, the only back compat issue by using a too generic variable name
 (like `$args` could be), could be a conflict with a variable with the same
 name used in template that has been locally scoped in other way (i.e.
 using  `include( locate_template() ) pattern`) or it has been already
 instantiated/used in template code.
 But IMHO this is a remote case and it will happen only if you will update
 your `get_template_part()` occurrences with the third argument.

 That's why initially I suggested to use `$wp_` prefix (i.e.
 `$wp_template_args`).

 PS: @justlevine the correct code of the 3rd line should be:
 {{{
 #!php
 get_template_part( 'foo', null, $args );
 }}}

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


More information about the wp-trac mailing list