Opened 9 years ago
Closed 9 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)
Change History (3)
Note: See
TracTickets for help on using
tickets.
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.