wpify/templates 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固