一个美丽的HTML标记库。
dev-master
2013-04-03 14:43 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-28 13:09:40 UTC
README
Composer
使用Composer安装Tagger非常简单,只需将以下要求添加到您的composer.json文件中
"bryantebeek/tagger": "v1.0.*"
使用方法
您可以通过在Tag类上调用所需的标签名称作为静态方法来开始使用Tagger。
Tagger\Tag::div(); Tagger\Tag::img();
添加内容
您可以在初始化标签时直接传递标签内容。
Tagger\Tag::div('Hello World!');
在直接传递内容之前,可以在标签初始化后设置内容。
Tagger\Tag::div()->content('Hello World!');
您还可以使用匿名函数设置标签内容。
Tagger\Tag::div(function ($tag) { return 'Hello World!'; });
添加属性
属性可以以多种方式设置。
// <div id="main"></div> Tagger\Tag::div()->id('main'); $tag = Tagger\Tag::div(); $tag->id = 'main';
请注意,一些HTML属性不能使用动态访问器设置,因为它们包含例如连字符。
// <div data-title="Hello World!"> Tagger\Tag::div()->setAttribute('data-title', 'Hello World!');
您还可以同时设置多个属性。
$attributes = array( 'id' => 'main', 'data-title' => 'Hello World!', ); Tagger\Tag::div()->setAttributes($attributes);
请注意,所有设置属性的方法都会返回对象,以允许链式调用。
渲染标签
将标签渲染到HTML有三种可能的方式。
$tag = Tagger\Tag::div(); // All following lines will output: <div></div> echo $tag; echo $tag->render(); echo $tag->open() . $tag->close();
检查属性
您可以检查标签是否具有某些属性。
$tag = Tagger\Tag::div()->id('main')->class('container'); $tag->hasAttribute('id'); // true $tag->hasAttributes(array('id', 'class')); // true $tag->hasAttributes(array('class', 'title')); // false