Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#36187 closed enhancement (duplicate)

Pass variables scoped to templates

Reported by: enricosorcinelli's profile 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)

36187.patch (7.2 KB) - added by enrico.sorcinelli 9 years ago.
36187.2.patch (9.6 KB) - added by enrico.sorcinelli 8 years ago.
Updated to trunk. This patch replaces the previous ones

Download all attachments as: .zip

Change History (6)

#1 @ocean90
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

Hello @enrico.sorcinelli, thanks for your ticket and patch, but it's actually a duplicate of #21676.

Last edited 9 years ago by ocean90 (previous) (diff)

@enrico.sorcinelli
8 years ago

Updated to trunk. This patch replaces the previous ones

#2 @enrico.sorcinelli
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

#3 @SergeyBiryukov
8 years ago

  • Version trunk deleted

Hi @enrico.sorcinelli, please upload the patch to #21676.

P.S. Version field indicates when the enhancement was initially suggested, not the current version.

#4 @enrico.sorcinelli
8 years ago

Hi @SergeyBiryukov,
I just added the patch also to #21676.

Note: See TracTickets for help on using tickets.