Pass a variable to get_template_part()
|Reported by:||sc0ttkclark||Owned by:|
|Cc:||knut@…, xoodrew@…, geertdd@…, contact@…, giulio.mainardi@…, johnzanussi, ian_dunn@…, lol@…|
Having the ability to pass a variable into get_template_part would be invaluable, it would really clean up the issues with using globals and to further cement it's use rather than the alternative of a normal PHP include/require.
It would be the third variable passed into get_template_part, which I could pass it a string, array, object, or whatever I want really. Here's an example of passing all the current scope's variables:
<?php get_template_part( 'twitter', 'feed', compact( array_keys( get_defined_vars() ) ) ); ?>
and then catching them in my feed-twitter.php file:
if ( !empty( $_data ) && is_array( $_data ) ) extract( $_data, EXTR_SKIP );
I can pass other things in, but that's a really valuable example in my uses for this new variable.
Change History (30)
- Keywords needs-testing added; dev-feedback removed
- Milestone changed from Awaiting Review to 3.5
- Keywords close added; needs-testing dev-feedback 2nd-opinion removed
- Milestone changed from Future Release to Awaiting Review