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

WordPress Trac noreply at wordpress.org
Mon Jun 8 18:27:01 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):

 I usually work around this limitation by using {{{set_query_var()}}}
 before calling {{{get_template_part()}}} so as not to pollute global
 scope. It does pollute the query vars array - but is generally safe as
 {{{template_include}}} fires after the main query/request has been made.

 This is a very annoying limitation to the WordPress templating system.
 Especially the fact that {{{get_template_part()}}} does not behave like
 PHP's native templating system - ie: {{{include}}} - which does recognize
 variables set in the scope where it was called. Leading to hack-ish
 workarounds like {{{include(locate_template())}}}.

 ----

 As for the latest patch. I don't much like the naming convention
 {{{$wp_tmpl_args}}}. I much prefer descriptive readable variable names:
 {{{$wp_template_args}}}, {{{$wp_template_vars}}}.

 Also since WP is moving towards integrating React perhaps {{{$props}}}
 would be a better naming convention  - alluding to React component props.
 React components are roughly equivalent to WP's {{{template_part}}}, and
 the usage of {{{$props}}} within the template/component is pretty much the
 same (PHP {{{<? ?>}}}tags instead of curly braces {{{{ }}}} ).

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


More information about the wp-trac mailing list