21/11
2017
A handy WordPress library to get image src with crop options.
An alternative to native Wordpress function get_template_part
that allows passing of arbitrary arguments to the template partial., (*1)
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., (*2)
Here's an example:, (*3)
// Anywhere in your theme templates get_template_part_args( 'template', 'part', [ 'example_argument' => true ] );
```php // in template-part.php, (*4)
// define defaults $defaults = [ 'example_argument' => false, ];, (*5)
// combine defaults with passed args $args = wp_parse_args( get_template_part_vars( $this ), $defaults );, (*6)