[wp-trac] [WordPress Trac] #21676: Pass a variable to get_template_part()
WordPress Trac
noreply at wordpress.org
Thu Aug 8 20:30:30 UTC 2013
#21676: Pass a variable to get_template_part()
-----------------------------+------------------------------
Reporter: sc0ttkclark | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Template | Version: 3.4.1
Severity: normal | Resolution:
Keywords: has-patch close |
-----------------------------+------------------------------
Changes (by amaschas):
* cc: amaschas (added)
Comment:
The fact that imported globals are widely used in Wordpress doesn't
mitigate the inherent drawbacks of the overuse of globals and the global
singleton pattern in development. We need to be able to scope variables to
templates for the same reason we need to scope variables anywhere, because
the global scope makes knowledge of the state of a variable difficult, and
reduces the modularity of code. At this point, getting variables into
template parts seems to involve building a maze of functionality around
managing imported globals, just to duplicate the functionality of local
scope.
I'm currently working on multiple projects that require building frontend
implementations of complex data structures, many of which contain repeated
nested elements. I end up wrestling with a choice of either building
enormously complex templates to handle the data object, or breaking the
elements into smaller templates and relying on imported globals in some
fashion. I've run into a number of situations where tracking the state of
multiple globals made testing and debugging much more difficult than they
needed to be. While I'm able to solve these problems, the solutions are
often byzantine, which is frustrating given that scoping is a solved
problem that helps code conform to the principles of OO design.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21676#comment:28>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list