wpify/templates
最新稳定版本:3.2.2
Composer 安装命令:
composer require wpify/templates
包简介
WPify Templates
README 文档
README
Abstraction over WordPress Templates.
Installation
composer require wpify/templates
Usage
use Wpify\Templates\WordPressTemplates; // Initialize the templates $template = new WordPressTemplates( array( plugin_dir_path( __FILE__ ) . 'templates', // path to template files in plugin trailingslashit( get_template_directory() ) . 'my-plugin', // path to template files in current theme ), ); // Print the html to frontend $template->print( 'my-template', 'test', array( 'some-args' => 'test' ) ); // Return the html $html = $template->render( 'my-template', 'test', array( 'some-args' => 'test' ) );
The above examples tries to find the templates in the following locations:
/wp-content/themes/current-theme/my-plugin-theme-folder/my-template.test.php/wp-content/themes/current-theme/my-plugin-theme-folder/my-template.php/wp-content/plugins/my-plugin/templates/my-template.test.php/wp-content/plugins/my-plugin/templates/my-template.php
Twig templates
You can also use twig templates for rendering. WordPress global variables and some functions are already registered.
use Wpify\Templates\TwigTemplates; // Initialize the templates $template = new TwigTemplates( array( plugin_dir_path( __FILE__ ) . 'templates', // path to template files in plugin get_template_directory() . 'my-plugin', // path to template files in current theme ), array( 'integrate' => true, // Allows twig templates for the current theme 'debug' => true, // Enable twig debug 'functions' => array( // Register custom functions. 'test_function' => function() { echo 'TEST'; }, ), 'filters' => array( // Register custom filters. 'test_filter' => function( $value ) { echo 'TEST:' . $value; }, ), 'globals' => array( // Register global variables. 'global_variable' => 'some value', ), 'namespaces' => array( 'blocks' => get_template_directory() . '/blocks', ), ) ); // Print the html to frontend $template->print( 'my-template', 'test', array( 'some-args' => 'test' ) ); // Return the html $html = $template->render( 'my-template', 'test', array( 'some-args' => 'test' ) );
统计信息
- 总下载量: 12.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2022-08-27