[wp-trac] [WordPress Trac] #36187: Pass variables scoped to templates
WordPress Trac
noreply at wordpress.org
Wed Mar 9 19:07:34 UTC 2016
#36187: Pass variables scoped to templates
-------------------------------+-----------------------------
Reporter: enrico.sorcinelli | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords:
Focuses: template |
-------------------------------+-----------------------------
This patch allows to pass variables scoped to template files.
The patch affects `load_template`, `locate_template` and `get_*` template
family functions.
For example:
{{{
get_template_part('parts/template', '', array( 'foo' => 'baz' ) );
}}}
and in ''parts/template.php'':
{{{
echo $params['foo'];
}}}
or:
{{{
get_header('header', '', array( 'foo' => 'baz') );
}}}
and so on.
I know, there are a lot ot threads, proposals, posts in the past that have
requested a similar functionality and I think that is the time to examine
again this for the 4.5 release.
Moreover, even if there are workarounds for that, like using globals, or
`include(locate_template())` pattern, the patch would really to clean up
those approaches.
In my opinion, abuse of globals is not too good practice and multiple
times the people just need to repeat bits of data on partial content (for
example loops which have considerable template HTML). And they would like
to reuse this template components across the site in more than one place
and or in different themes creating a sort of their own templates codebase
repository.
---
PS: Since it seems that there is no a clean way to test
`locate_template()` (and consequently `get_*` template functions) with a
different theme other than `twentyfifteen` even after switching a theme
(that is, themes inside `tests/phpunit/data` directory), the only unit
test currently I added is for `load_template()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36187>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list