[wp-trac] [WordPress Trac] #21676: Pass a variable to get_template_part()
WordPress Trac
noreply at wordpress.org
Tue Feb 19 19:09:45 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 wonderboymusic):
* keywords: has-patch needs-testing dev-feedback 2nd-opinion => has-patch
close
* milestone: Future Release => Awaiting Review
Comment:
I think passing `$data` or `$args` down the chain is worse than importing
globals. `load_template()` imports a bunch of globals, that's how function
scope in PHP works. Is it better to import those variables using an
argument to `load_template()`? That's not even the question being asked,
the question is how to jam more data in there, and the answer is simple:
import those globals in your function. If you hate global scope, limit
your app's global pollution to one object - for instance, I use an
`$emusic` global variable (`stdClass`), and I have a `get_emusic()`
function to retrieve it, so I import zero globals, yet always have access
to them:
{{{
function where_are_my_vars() {
$vars = get_emusic()->right_here;
}
}}}
Suggesting close / wontfix
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21676#comment:24>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list