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

WordPress Trac noreply at wordpress.org
Mon Aug 26 21:31:16 UTC 2013


#21676: Pass a variable to get_template_part()
-----------------------------+-------------------------
 Reporter:  sc0ttkclark      |       Owner:
     Type:  enhancement      |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Template         |     Version:  3.4.1
 Severity:  normal           |  Resolution:  maybelater
 Keywords:  has-patch close  |
-----------------------------+-------------------------
Changes (by nacin):

 * resolution:  wontfix => maybelater


Comment:

 Replying to [comment:43 sc0ttkclark]:
 > I believe I've put some strong arguments for passing a variable/args
 and/or scoping variables for get_template_part. I haven't heard a
 compelling enough argument against all of these potential options, and it
 seems like there are others who have been having the same concerns.
 >
 > Core Devs: Is there not enough merit in this function having this
 ability, or another function created with child/parent theme aware
 including of a file and passing that file an arg array or to scope vars?

 I don't think the reasoning behind the votes for close/wontfix are very
 strong. But I do think this should be closed for now.

 Is there merit in ''a'' function having this ability? Actually, yes.

 bbPress 1.x has similar functionality:
 http://bbpress.trac.wordpress.org/browser/branches/1.1/bb-
 includes/functions.bb-template.php#L3. bb_load_template() essentially
 allows someone to pass an array of variables that then get pulled in. I
 wouldn't implement it exactly like this, and I'd probably lean off global
 scope a bit, but either way, this isn't a new idea.

 But is there merit in ''this'' function having this ability? That I am
 less sure about — get_template_part() is designed to do one thing, and in
 order to do that, it requires two arguments. Adding another argument that
 does something goofy like passing scoped arguments is probably *not* the
 best way to do this. It's possible, based on type-juggling, to let the
 second *or* third argument (if the current second argument isn't used) to
 be an array of variables.

 Whether we introduce a new function or overload this function's arguments,
 there is still the issue of education. Passing variables around is not an
 easy concept to explain. Many theme developers are not developers at all.
 I would hesitate to add anything to this API without clearing setting a
 new standard for theme development, much the way get_template_part() did.
 For example, if we did this, I would want a clean break from all global
 scope. That means sidestepping locate_template() and load_template(),
 which would also mean a significantly simpler call stack and less of a
 rabbit hole for loading a template.

 And since you don't want all of that globals magic, it's very simple to
 roll your own function for now, for however it may suit you.

 Once nice thing about get_template_part() is it is a relatively new
 function (2-3 years) and people are still trying to figure out how to best
 leverage it. Even core has opted for a few different patterns through four
 default themes. There are also various theme frameworks and platforms out
 there that allow for ample opportunity for experimentation.

 I don't think this is a ''wontfix''. I do however think it is a
 ''maybelater''. I think it is something that we should put in our back
 pocket and come back to it in a few months or longer and see how it feels
 then.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/21676#comment:44>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list