定制 imponeer/smarty-includeq 二次开发

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

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

imponeer/smarty-includeq

Composer 安装命令:

composer require imponeer/smarty-includeq

包简介

Rewritten smarty 'include' variant that was invented for use in XOOPS, but nowadays is used in some other PHP based CMS'es

README 文档

README

License GitHub release PHP Packagist Smarty version requirement

Smarty IncludeQ

This library provides a rewritten version of the Smarty {include} tag variant originally developed for XOOPS CMS. The {includeq} tag offers enhanced template inclusion capabilities and is now used across various PHP-based content management systems, including ImpressCMS.

This implementation was created as a clean-room rewrite to avoid GPL licensing constraints while maintaining full compatibility with the original functionality. The plugin extends Smarty's template inclusion system with additional features specifically designed for CMS environments.

For reference, see the original XOOPS implementation to understand the historical context and requirements this plugin addresses.

Installation

To install and use this package, we recommend to use Composer:

composer require imponeer/smarty-includeq

Otherwise, you need to include manually files from src/ directory.

Setup

Modern Smarty Extension (Recommended)

For Smarty 5.x, use the modern extension system by adding the extension to your Smarty instance:

// Create a Smarty instance
$smarty = new \Smarty\Smarty();

// Register the IncludeQ extension
$smarty->addExtension(new \Imponeer\Smarty\Extensions\IncludeQ\IncludeQExtension());

Legacy Plugin Registration

For compatibility with older Smarty versions or legacy code, you can register the compiler directly:

$smarty = new \Smarty();
$includeqPlugin = new \Imponeer\Smarty\Extensions\IncludeQ\IncludeQCompiler();
$smarty->registerPlugin('compiler', 'includeq', [$includeqPlugin, 'compile']);

Using with Dependency Injection Containers

Symfony Container

To integrate with Symfony, you can leverage autowiring:

# config/services.yaml
services:
    _defaults:
        autowire: true
        autoconfigure: true

    # Configure Smarty with the extension
    \Smarty\Smarty:
        calls:
            - [addExtension, ['@Imponeer\Smarty\Extensions\IncludeQ\IncludeQExtension']]

PHP-DI Container

With PHP-DI container:

use function DI\create;
use function DI\get;

return [
    \Smarty\Smarty::class => create()
        ->method('addExtension', get(\Imponeer\Smarty\Extensions\IncludeQ\IncludeQExtension::class))
];

League Container

If you're using League Container, you can register the extension like this:

// Create the container
$container = new \League\Container\Container();

// Register Smarty with the IncludeQ extension
$container->add(\Smarty\Smarty::class, function() {
    $smarty = new \Smarty\Smarty();
    // Configure Smarty...

    // Create and add the IncludeQ extension
    $extension = new \Imponeer\Smarty\Extensions\IncludeQ\IncludeQExtension();
    $smarty->addExtension($extension);

    return $smarty;
});

Then in your application code, you can retrieve the Smarty instance:

// Get the configured Smarty instance
$smarty = $container->get(\Smarty\Smarty::class);

Usage

The {includeq} tag provides enhanced template inclusion capabilities with support for variable passing and output assignment.

Basic Template Inclusion

Simple template inclusion:

{includeq file="header.tpl"}

Passing Variables to Included Templates

You can pass variables to the included template:

{includeq file="user_profile.tpl" user_id=123 show_avatar=true}

Assigning Output to a Variable

Capture the output of the included template into a variable:

{includeq file="sidebar.tpl" assign="sidebar_content"}
{* Now you can use $sidebar_content variable *}
<div class="main-content">
    {$sidebar_content}
</div>

Advanced Examples

Including with dynamic file names:

{includeq file="modules/{$module_name}/template.tpl" module_data=$data}

Conditional inclusion with assignment:

{if $show_sidebar}
    {includeq file="sidebar.tpl" assign="sidebar" user=$current_user}
{/if}

Including with complex variable passing:

{includeq file="product_list.tpl"
          products=$products
          show_prices=true
          currency="USD"
          per_page=20}

Development

Code Quality Tools

This project uses several tools to ensure code quality:

  • PHPUnit - For unit testing

    composer test
  • PHP CodeSniffer - For coding standards (PSR-12)

    composer phpcs    # Check code style
    composer phpcbf   # Fix code style issues automatically
  • PHPStan - For static analysis

    composer phpstan

Documentation

API documentation is automatically generated and available in the project's wiki. For more detailed information about the classes and methods, please refer to the project wiki.

Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request

Please make sure your code follows the PSR-12 coding standard and include tests for any new features or bug fixes.

If you find a bug or have a feature request, please create an issue in the issue tracker.

imponeer/smarty-includeq 适用场景与选型建议

imponeer/smarty-includeq 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.8k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 imponeer/smarty-includeq 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-03