mentormate / template-part-args
A handy WordPress library to get image src with crop options.
1.0
2017-11-21 10:12 UTC
This package is not auto-updated.
Last update: 2025-06-13 06:25:13 UTC
README
An alternative to native Wordpress function get_template_part
that allows passing of arbitrary arguments to the template partial.
How to use
There are two template functions exposed by the plugin - get_template_part_args
and get_template_part_vars
. The former is used in place of get_template_part
, i.e. to pass the arguments and the latter is used to retrieve them in the template partial.
Here's an example:
// Anywhere in your theme templates get_template_part_args( 'template', 'part', [ 'example_argument' => true ] );
// in template-part.php // define defaults $defaults = [ 'example_argument' => false, ]; // combine defaults with passed args $args = wp_parse_args( get_template_part_vars( $this ), $defaults );