php - Is there a way to have $args suggestions when using a template part?
one text
I work in a WP project using template parts, as they are multiple buttons instance in this project i created a button template that can take multiple arguments as such:
<?
/**
* Default button template
*
*/
$container_classes = $args["container_classes"]; //additional container classes
$button_type = $args['button_type']; // link | button | modal
$elem_classes = $args['elem_classes']; //additional classes for the button
$url = $args['url'] ?? null; //provides the url target
$text = $args['text'] ?? null; // text to display inside the button
$text_color = $args['text_color'] ?? "white"; // text color
$bg_color = $args['bg_color'] ?? 'cta';
$target = $args['target'] ?? "_self"; //target attribute
$icon = $args['icon'] ?? null; //If there is an icon, link to the icon
$modal_slug = $args['modal_slug'] ?? 'null'
?>
<div class="button-<?= $button_type ?> flex <?= $container_classes ?>">
{... All the button specifications and other logical checks ... }
</div>
I would now like to use this template in multiple sections. But with all those $args i would like to have suggestions when typing in the arguments in the get_template_part() function.
Is there a way of defining the possible $args in the template-part file as i've seen it being used in functions for instance ?
Exemple of predefined params for a function:
function get_template_part( $slug, $name = null, $args = array() ) {
/**
* Fires before the specified template part file is loaded.
*
* The dynamic portion of the hook name, `$slug`, refers to the slug name
* for the generic template part.
*
* @since 3.0.0
* @since 5.5.0 The `$args` parameter was added.
*
* @param string $slug The slug name for the generic template.
* @param string|null $name The name of the specialized template.
* @param array $args Additional arguments passed to the template.
*/
where the @param notation defines expected parameters.
I'm trying to have suggestion proposed by VsCode when using a template part and trying to figure out a way for the $args to reproduce the params behavior in the case of a function.
Source