wp-router icon indicating copy to clipboard operation
wp-router copied to clipboard

Feature request: Reusable templates

Open drewbaker opened this issue 1 year ago • 2 comments

I'd love to be able to make templates reusable, and then also be able to get the name of the active template.

I think it can be done without a breaking change, and would make the router really really powerful!

So I could do something like this:

// router.php
$router = new MakeitWorkPress\WP_Router\Router( 
    [
        'film'        => ['route' => film/, 'template' => 'video.php'],
        'tv'           => ['route' => tv/, 'template' => 'video.php'],
        'music'    => ['route' => music/] // defaults to key as template name, so music.php        
    ], 
);
// video.php
if( get_current_route() == 'film' ) {
    // Some code unique to film route
}

This would make my templates more reusable, and allow me to keep my route based logic all based on the config in my router.php file.

drewbaker avatar Jul 31 '24 21:07 drewbaker