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

WordPress Trac noreply at wordpress.org
Wed Jul 1 19:26:59 UTC 2020


#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 needs-testing  |     Focuses:
-------------------------------------+------------------------------

Comment (by apedog):

 There are 2 discussions being had here at the moment.
 The first is whether a third parameter should be added to allow passing
 variables to the template part.
 On that discussion I am wholeheartedly a +1 for adding this feature. It is
 a useful pattern to me. And it is not detrimental to those who do not wish
 to pass variables to their template parts.

 The second discussion is the implementation discussion.
 The second discussion is only relevant if WP goes forward and implements
 this feature.
 As a user of this pattern I would very much like to access my variables
 directly within the templates. ie. {{{$var_name}}} and not
 {{{$args['var_name']}}}

 As stated above by John and Sergey this poses some technical and standards
 issues that would need to be hashed out:

 The first is the technical issue of protecting global variable names like
 {{{$post}}}. This can and should be done.

 The second is the coding standards issue of using PHP's {{{extract()}}}
 which is discouraged outside of {{{load_template()}}}. As this feature IS
 implemented in {{{load_template()}}} and IS attempting to offer the same
 option as {{{set_query_var()}}} currently allows - direct access to
 variables - it is my opinion that {{{extract()}}} can be justified here as
 well.

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


More information about the wp-trac mailing list