htmlburger / wpemerge-theme

An organized, ES6 and SASS powered theme taking advantage of the WP Emerge framework. 🚀
https://wpemerge.com/
GNU General Public License v2.0
286 stars 33 forks source link

Overriding WooCommerce templates #24

Closed sybbear closed 5 years ago

sybbear commented 5 years ago

Hey, thank you for developing such a good starter theme.

It's been working smoothly, however there is one issue regarding woocommerce.

Some templates need to be overridden, however WP Emerge does not fallback to lookup for views in woocommerce plugin. This makes it necessary to copy all files into theme/woocommerce directory.

Is there a workaround for this?

Would be very grateful for help!

atanas-dev commented 5 years ago

Hi @vikingmaster ,

Could you please share your route definition so I can have a better understanding of the problem? Also I assume you are calling return app_view( 'some-woo-template.php' ) in your controller method, correct?

sybbear commented 5 years ago

No extra routes used, just a generic woocommerce webshop. And a clean WP Emerge theme with BladeVIew.

Steps to reproduce:

Is there any docs / instructions how to make WP Emerge work with WooCommerce templates?

atanas-dev commented 5 years ago

I'll have to take a look later today - will post an update when I do.

atanas-dev commented 5 years ago

Confirmed the issue - it is due to a limitation of the Blade extension for WP Emerge. I'll make sure the issue is addressed in the next version - thanks!

sybbear commented 5 years ago

Thank you! Eagerly looking forward to seeing WP Emerge working with WooCommerce 💪

atanas-dev commented 5 years ago

Just to clarify - WP Emerge works just fine with WooCommerce if you use the default PHP template engine - it's the Blade for WP Emerge extension that is faulty.

Writing this reminded me that there's a better workaround using NameProxyViewEngine:

// getContainer() used for brevity's sake - use a Service Provider instead.
$container = WPEmerge::getContainer();
$container[ WPEMERGE_VIEW_ENGINE_KEY ] = function( $container ) {
    return new \WPEmerge\View\NameProxyViewEngine( [
        '.blade.php' => WPEMERGEBLADE_VIEW_BLADE_VIEW_ENGINE_KEY,
        '.php' => WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY,
        // use Blade for all other cases as blade views can be referenced
        // in blade.format.as.well without an extension
    ], WPEMERGEBLADE_VIEW_BLADE_VIEW_ENGINE_KEY );
};

With this all .php templates will be rendered using the default view engine (so you don't have to copy them in your theme) while your theme's blade templates will be rendered using Blade.

sybbear commented 5 years ago

Can confirm, that this workaround works, appreciated 👍

atanas-dev commented 5 years ago

A new proxy_php_views option is now available in master which automatically covers this use case so keep an eye out for when it goes live in the next release.