WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#33859 closed enhancement (duplicate)

Custom variables in get_template_part

Reported by: sebastian.pisula Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Themes Keywords:
Focuses: Cc:

Description

For example:

get_template_part('page', 'part', array('username'=>'Sebastian'));

And in page-part.php

Hello, <?php echo $username;?>

Attachments (1)

custom-variables.patch (3.2 KB) - added by sebastian.pisula 6 years ago.

Download all attachments as: .zip

Change History (3)

#1 @nofearinc
6 years ago

I like the idea of being able to make template parts more dynamic without introducing global variables or perform numerous checks (including database calls in the "views").

However I don't think that extract is a good idea though since it pollutes the current symbol table and could lead to various issues. It has been gradually removed from Core in #22400. Probably working with the $params array directly would do just fine.

#2 @SergeyBiryukov
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #21676.

Note: See TracTickets for help on using tickets.