Skip to content
Snippets Groups Projects
Verified Commit c4d9b51b authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

feat: add WooTemplateResolver


Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
parent 4c440080
Branches feat/woo-template
No related tags found
2 merge requests!9feat: add WooTemplateResolver,!8feat/woo template
Pipeline #376476 passed with stages
in 8 seconds
## Unreleased
### Added
- Introduced `WooTemplateResolver` for template paths and overrides in WooCommerce spirit.
## [2.0.0] - 2021-10-01
### Added
- Add output_render method to Renderer interface
## [1.1.0] - 2019-09-23
### Added
- PluginViewBuilder to facilitate building and rendering views for plugins
\ No newline at end of file
- PluginViewBuilder to facilitate building and rendering views for plugins
<?php
declare(strict_types=1);
namespace WPDesk\View\Resolver;
use WPDesk\View\Renderer\Renderer;
use WPDesk\View\Resolver\Exception\CanNotResolve;
/**
* Locate templates, respecting WooCommerce template load order, prepending custom path to seek for templates. This supports user's template overrides by default.
*/
class WooTemplateResolver implements Resolver {
/** @var string */
private $base_path;
public function __construct( string $base_path ) {
if ( ! function_exists( 'wc_locate_template' ) ) {
throw new \RuntimeException( sprintf( 'The "%s" resolver needs the WooCommerce plugin. Make sure it is installed and active.', __CLASS__ ) );
}
$this->base_path = $base_path;
}
public function resolve( $name, Renderer $renderer = null ): string {
$template = wc_locate_template( $name, '', $this->base_path );
if ( $template === '' ) {
throw new CanNotResolve( "Cannot resolve template {$name}" );
}
return $template;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment