Download the PHP package wpdesk/wp-view without Composer
On this page you can find all versions of the php package wpdesk/wp-view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wp-view
WP View
WP View is a lightweight PHP library for rendering PHP templates. It can be used as a standalone renderer and also provides resolvers for WordPress theme overrides and WooCommerce-style template loading.
Requirements
- PHP 7.4 or later, including PHP 8.x.
- Composer.
- WordPress is required when using
WPThemeResolverorPluginViewBuilder. - WooCommerce is required when using
WooTemplateResolver.
Installation via Composer
Install the package with Composer:
Composer autoloads the library with the WPDesk\View\ namespace.
Basic usage
SimplePhpRenderer renders a PHP template resolved by a resolver. The renderer
adds the .php extension, so template-name resolves to template-name.php.
Inside templates/template-name.php, array keys passed to render() are
available as local variables:
Multiple template directories
Use ChainResolver when templates can be loaded from more than one location.
Resolvers are checked in the order in which they are added, and the first
matching template is used.
In this example, templates/overrides/template-name.php is used when it exists.
Otherwise, the renderer falls back to templates/default/template-name.php.
WordPress plugin usage
PluginViewBuilder creates a default renderer for plugin templates. It looks
for theme overrides first and falls back to templates bundled with the plugin.
For a plugin directory named example-plugin, the default lookup order is:
- Child theme path:
example-plugin/template-name.php. - Parent theme path:
example-plugin/template-name.php. - Plugin path:
templates/template-name.php.
You can also render directly through the builder:
WooCommerce templates
Use WooTemplateResolver when templates should follow WooCommerce's template
lookup behavior, including theme overrides handled by wc_locate_template().
Main components
WPDesk\View\Renderer\SimplePhpRendererrenders PHP templates and returns output as a string.WPDesk\View\Renderer\Rendererdefines the renderer interface.WPDesk\View\Resolver\DirResolverresolves templates from a directory.WPDesk\View\Resolver\WPThemeResolverresolves templates through WordPresslocate_template().WPDesk\View\Resolver\WooTemplateResolverresolves templates through WooCommercewc_locate_template().WPDesk\View\Resolver\ChainResolvertries multiple resolvers in order.WPDesk\View\Resolver\NullResolveris a resolver implementation that always fails.WPDesk\View\Resolver\Exception\CanNotResolveis thrown when a template cannot be resolved.WPDesk\View\PluginViewBuilderbuilds the default WordPress plugin renderer.
Development
Install dependencies before running local checks:
Available Composer scripts:
License
This package is released under the MIT License.