定制 nguereza-tony/codeigniter-twig 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nguereza-tony/codeigniter-twig

Composer 安装命令:

composer require nguereza-tony/codeigniter-twig

包简介

Integrate Twig to CodeIgniter 4

README 文档

README

Integrate Twig to CodeIgniter 4.

Setup

Download package using composer.

composer require nguereza-tony/codeigniter-twig

Open APPPATH/Controllers/BaseController.php.

use Nongbit\Twig\Traits\Twig;

abstract class BaseController extends Controller
{
    use Twig;

    ...

    public function initController(...)
    {
        ...

        $this->initTwig();
    }
}

Usage

Template

To display template, we can use display() provided by the trait.

$this->display('hello', ['title' => 'Acme'])

By default, Twig will look for template files inside APPPATH/Views. To add other locations use addPath().

$this->twig->addPath(ROOTPATH . 'templates');

The default file extension is html but we can change it by creating a configuration file App\Config\Twig.php.

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Twig extends BaseConfig
{
    public string $fileExtension = 'twig';
}

Global

$this->twig->addGlobals('title', 'Acme');
$this->twig->addGlobals(['title' => 'Acme']);

Inside view:

{{ title }}

Filter

$this->twig->addFilters('rot13', 'rot13');
$this->twig->addFilters('rot13', function($string) {
    return str_rot13($string);
});
$this->twig->addFilters(['rot13']);

Inside view :

{{ 'Twig'|rot13 }}

Function

Function behaves similarly to a filter.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固