定制 netzmacht/html 二次开发

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

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

netzmacht/html

最新稳定版本:3.0.0

Composer 安装命令:

composer require netzmacht/html

包简介

Simple library for html rendering

关键字:

README 文档

README

Build Status Version License Downloads

This library is a PHP helper library for creating HTML output.

Install

This extension can be installed using Composer

composer require netzmacht/html:^3.0

Requirements

PHP ^8.1

Basic Usage

Define the attributes in the View:

Attributes

$attributes = new Netzmacht\Html\Attributes();
$attributes
    ->setId('a_id')
    ->addClass('a_class')
    ->setAttribute('data-target', '#some');

This library uses the magic __toString to converts the helper objects to string. Outputting is really simple now:

<div <?= $attributes; ?>><span class="label">Label</span> This is a paragraph.</div>

Of course you can change the attributes before generating

<div <?= $attributes->setId('second')->removeClass('a_class')->addClass('new_class'); ?>>the content</div>

Elements

Of course you can create the whole element as well. The library knows about standalone html elements which can't have any children and nodes which have children. Notice that the css classes are passed as array.

$factory   = new Netzmacht\Html\Factory\ElementFactory();
$paragraph = $factory->create('p', array('id' => 'a_id', 'class' => array('description'));
$label     = $factory->create('span');

$label
    ->addClass('label')
    ->addChild('Label this');

$paragraph
    ->addChild('This is a paragraph.')
    ->addChild(' '); // add space between both elements
    ->addChild($label, Netzmacht\Html\Element\Node::POSITION_FIRST); // add at first position    

Now you can output the whole element:

<article>
    <?= $paragraph; ?>
</article>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2014-05-15