#36187 closed enhancement (duplicate)
Pass variables scoped to templates
Reported by: | enrico.sorcinelli | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | |
Focuses: | template | Cc: |
Description
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()
.
Attachments (2)
Change History (6)
#1
@
9 years ago
- Component changed from General to Themes
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
- Version trunk deleted
#2
@
8 years ago
- Version set to trunk
I just updated the patch to trunk.
I would to get back on track with this long awaited and requested enhancement.
See comment:58:ticket:21676
Hello @enrico.sorcinelli, thanks for your ticket and patch, but it's actually a duplicate of #21676.