定制 noraziz/ci4-twiggy 二次开发

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

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

noraziz/ci4-twiggy

Composer 安装命令:

composer require noraziz/ci4-twiggy

包简介

Twig template engine implementation for CodeIgniter 4, forked from https://github.com/edmundask/codeigniter-twiggy.

README 文档

README

This library is for Codeigniter 4, forked from twiggy. But, some development reference come from ss-twig & raizdev.

Twiggy is not just a simple implementation of Twig template engine for CodeIgniter. It supports themes, layouts, templates for regular apps and also for apps that use modular support, see: Code Modules.

It is supposed to make life easier for developing and maitaining CodeIgniter applications where themes and nicely structured templates are necessary.

Why Should I Care?

For some reason, the original twiggy library is moved to new structure so you can add this library to your projects using composer. Twig by itself is a very powerful and flexible templating system but with CodeIgniter it is even cooler! With Twiggy you can separately set the theme, layout and template for each page. What is even more interesting, this does not replace CodeIgniter's default Views, so you can still load views as such: $this->load->view().

Demo

Visit our demo repository github.

Our wiki is coming soon.

Features:

  • Theme path & twig template may be placed on module. Default on 'app' folder.
  • Set/Unset custom variable to be passed to template.
  • Set/Unset meta (html template).
  • Add Function (mode: as-is or safe).
  • Add Filter.
  • Set template title. You may combine with function 'append' or 'prepend' for formatting words.
  • Set custom theme.
  • Set custom layout, default layout path is: '{app-mod}\Themes{theme_name}_layout'.
  • Set custom template, default file extension: 'html.twig'.
  • Use 'display' method for directly output to browser. Else use 'render' method to capture parsed template.

Default Functions:

  • as-is: base_url, site_url.
  • safe: form_open, form_close, form_error, form_hidden, set_value, csrf_field.
  • built-in: getConfig, getLang, safe_anchor, validation_list_errors.

Requirements

  • PHP 7.3 or later
  • CodeIgniter 4.2 or later
  • Twig 3.3.8 or later

Installation

With Composer

$ cd /path/to/codeigniter/
$ composer require noraziz/ci4-twiggy

Usage

Set up dir structure

  1. Create a directory structure:

    +-{APPPATH}/
    | +-Themes/
    | | +-default/
    | | | +-_layouts/
    

    NOTE: {APPPATH} is the folder where all your controllers, models and other neat stuff is placed. By default that folder is called app. Themes directory can also inside your module.

    +-{APPPATH}/
    | +-Config/
    | +-Controllers/
    |
    +-Modules/
    | +-{Module-Name}/
    | | +-Themes/
    | | | +-default/
    | | | | +-_layouts/
    
  2. Create a default layout index.html.twig and place it in _layouts folder:

    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8">
    		<!--[if lt IE 9]>
    		<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    		<![endif]-->
    		<title>Default layout</title>
    	</head>
    	<body>
    
    		{% block content %}
    
    
    
    		{% endblock %}
    		
    	</body>
    </html>
  3. Create a default template file index.html.twig at the root of default theme folder:

    {% extends _layout %}
    
    {% block content %}
    
    	Default template file.
    
    {% endblock %}
  4. You should end up with a structure like this:

    +-{APPPATH}/
    | +-Themes/
    | | +-default/
    | | | +-_layouts/
    | | | | +-index.hml.twig
    | | | +-index.html.twig
    

Initialize Twiggy

You must maually initialize twiggy engine.

$twiggy = new \noraziz\ci4twiggy\Twiggy();
$twiggy->init(__CLASS__);

Display the template

Render Twig template and output to browser:

$twiggy->display();

What's next?

In the example above we only displayed the default template and layout. Obviously, you can create as many layouts and templates as you want. For example, create a new template file page_welcome.html.twig and load it before sending the output to the browser.

$twiggy->layout('layout_model_1');
$twiggy->template('page_welcome');

//or using chaining
$twiggy->layout('layout_model_1')->template('page_welcome');

Notice that you only need to specify the name of the template (without the extension *.html.twig).

References

Documentation

@TODO

noraziz/ci4-twiggy 适用场景与选型建议

noraziz/ci4-twiggy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「twig」 「library」 「codeigniter」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 noraziz/ci4-twiggy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 noraziz/ci4-twiggy 我们能提供哪些服务?
定制开发 / 二次开发

基于 noraziz/ci4-twiggy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-30