coercive/template 问题修复 & 功能扩展

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

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

coercive/template

最新稳定版本:0.0.0

Composer 安装命令:

composer require coercive/template

包简介

Coercive Utility for building template from array data

README 文档

README

Build template from array data (so from converted Yaml or Json too)

Get

composer require coercive/template

Array structure

Please see /sample/example.xml

The field wrapper is use to place some html arround your content.

Set {{content}} inside the wrapper where your want to place your content.

The field content will be injected there.

You can also don't use it and place everything you need inside the wrapper directly.

The other fields id, type, class ... are setted to do checks, loops, inject specific content for a given id etc...

Basic load

use Coercive\Utility\Template\ArrayLoader;

# ArrayLoader returns multiple template, so if only one we take it by using [0] (the first row in array).
$template = ArrayLoader::load([$mapped])[0] ?? null;

# If you need to use some methods based on a map system, you have to load maps by using automap method.
if($template) {
    $template->automap();
}

# Render the template
echo $template->getHtml();

Useful methods

Apply automaticaly the tag {{content}} to main template wrapper that don't have one.

$template->setDefaultContentWrapperIfEmpty();

Apply automaticaly the tag {{content}} to positions wrapper that don't have one, and match the given types.

$template->setDefaultContentWrapperForAllByTypes(['your_first_type_to_check', 'your_second_type_to_check']);

Work with types, ids, classes, namespaces, or all (no extra-check).

You have lot's of getters and setters to retrieve or set some data

# See constant options on top of the class.
echo $template->getInternalId();
echo $template->getInternalClass();
echo $template->getInternalNamespace();
echo $template->getInternalType();

Access to data field. (use Coercive/Container)

echo $template->data()->get('something');

Inject custom blocks that require internal preparation by your system.

foreach ($template->getPositionByType('custom') as $position) {
    if($position->data()->get('item_type') === 'SLIDE' && $code = (int) $position->data()->get('item_code')) {
        $slide = $$$_Get_Your_Data_Here_For_Example($code);
        if($slide) {
            $html = $$$_Get_Render_System_Here_For_Example('template/example/slide', ['slide_data' => $slide]);
            $position->setWrapper($html); // or setContent() if you have a wrapper to use
        }
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固