承接 northrook/html-element 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

northrook/html-element

Composer 安装命令:

composer require northrook/html-element

包简介

A collection of classes for generating HTML elements and their attributes.

README 文档

README

Generate HTML elements and their attributes.

The motivation behind this package is to provide a simple way to generate HTML elements with sensible defaults, while being more light-weight than the DOMDocument class.

Elements can be nested to create complex HTML structures, but unlike DOMDocument it does not provide a way fully traverse the DOM tree.

This is a deliberate design decision to keep the package lightweight and performant.

Important

This package is still in development.

While it is considered MVP and stable, it may still undergo breaking changes.

Note

Documentation is still being written.

Installation

composer require northrook/html-element

Usage

New elements can be created using the Element class:

namespace Northrook\HTML\Element;

$basic = new Element( content: 'Hello World!' );

echo $basic;
<div>Hello World!</div>

Elements can be nested using the $content parameter. It accepts strings, Elements, and arrays of either.

Important

The Element class does not escape provided $content, so ensure you do so either before passing it, or later down the line.

echo new Element( 'h1', [ 'class' => 'example classes' ], $basic );
<h1 class="example classes">
    <div>Hello World!</div>
</h1>
$button = new Element(
    tag        : 'button',
    attributes : [ 'id' => 'Save Action', 'class' => 'btn icon' ],
    content    : [
        new Element( 'i', content: '<svg ... </svg>' ),
        'Save',
    ]
);

echo $button;
<button id="save-action" type="button" class="btn icon">
    <i>...</i>
    Save
</button>

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-25