wp-papi / papi

:rocket: WordPress Page Type API with custom fields
https://wp-papi.github.io
MIT License
263 stars 32 forks source link

add_filter for page template $extension #230

Closed Log1x closed 7 years ago

Log1x commented 7 years ago

Could you add a quick filter for the $extension variable located at #L33 of template.php.

I'd do a PR but not sure what naming scheme you want to use.

An example would be:

$extension = apply_filters( 'papi/template_extension', '.php' );

I want this filter for use of Papi in Sage 9 with Blade integration.

Example:

add_filter('papi/template_extension', function () {
    return '.blade.php';
});

Works wonderfully with my filter above and a filter for papi/template_include such as:

add_filter('papi/template_include', function ($template) {
    $data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
        return apply_filters("sage/template/{$class}/data", $data, $template);
    }, []);
    echo template($template, $data);
    return get_theme_file_path('index.php');
});

-- without the filter for $extension, my page.blade.php becomes page/blade.php.

I know this is a weird use-case, but it'd be much appreciated.

Thanks.

frozzare commented 7 years ago

You can do a PR with the example you provided

$extension = apply_filters( 'papi/template_extension', '.php' );
frozzare commented 7 years ago

Merged https://github.com/wp-papi/papi/pull/231

entr commented 6 years ago

Also it might be useful to note that you need to define your template in Papi_Page_Type::meta() without the extension like 'template' => 'views/papi/video', or this won't work.