PHPackages                             amsrafid/tagger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. amsrafid/tagger

ActiveLibrary[Templating &amp; Views](/categories/templating)

amsrafid/tagger
===============

Perfect view builder for php with inbuilt control statement.

1.0.0-beta(5y ago)31MITPHPPHP ^5.6 || ^7.0

Since Jul 31Pushed 5y ago1 watchersCompare

[ Source](https://github.com/amsrafid/tagger)[ Packagist](https://packagist.org/packages/amsrafid/tagger)[ RSS](/packages/amsrafid-tagger/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Tagger
======

[](#tagger)

One of the most flexible html view builder for php. It builds view in php file using same naming convention of html tag and attributes.

Installation
============

[](#installation)

This is a composer package. So, require this package in the `composer.json` of your php/framework project or run the command bellow,

```
composer require amsrafid/tagger

```

Basic use
=========

[](#basic-use)

Very easy to use. Attribute and tag name is same as normal html. Most notable fact is that ***sudo*** or short name is also worked as normal HTML attributes.

```
\Html\Tag::{Tag name}([
	'i/id' => 'id-name',
	'c/cls/class' => 'class-name',
	'd-./_./*./data-.' => 'data-value',
	'b/body/txt/text' => string|array|number|bool|function(){} /* tag body*/
	...
]);
```

Array key refers attribute name and key value as attribute value.
Note: Data attribue is also handled with sudo as like ***\[d-name/\_name/\*name\]***.
In all cases above, attribute name will be ***data-name***.

### Attribute ***'body'***:

[](#attribute-body)

Attribute ***body*** is the nested part of a tag. Body can be of five types. String or number is basic type. Special types are,

- ***Array* type:**
    - Here, only ***associative*** array is allowed to show. In that case, ***arry key*** denotes ***tag name*** and ***value*** is a ***sequential array*** where each value is the body of each tag named in main array key.
    - Example:

    ```
     use Html\Tag;

     Tag::ul(['b' => ['li' => ['one', 'two', 'three']]]);
    ```

    - Output:

    ```

     	one
     	two
     	three

    ```
- ***Object* type:**
    - Returns *string*, *number* or *associative array* to be shown in body.
    - Mainly, object type denotes a ***function*** that contains nested elements of mother tag.
    - Example:

    ```
     Tag::div(function(){
     	Tag::h4("First set:");
     	Tag::hr();
     	Tag::div(['b' => 'Having fun, isn\'t it?']);
     	Tag::div(function(){
     		Tag::span(function(){ return "One"; });
     		Tag::span(2);

     		return [
     			'h3' => ['array', 'returned'],
     			'u' => ['test', 'underline'],
     		];
     	});
     });
    ```

    - Output:

    ```

     	First set:

     	Having fun, isn't it?

     		One
     		2
     		array
     		returned
     		test
     		underline

    ```
- ***Boolean* type**
    - Boolean type works when there is nothing to show on body. But, The tag is not a single tag like, ``. Then, body value should be given as **true**.
    - Example:

    ```
     Tag::script(["s"=>"https://script.js", 'b' => true]);
    ```

    - Output:

    ```

    ```

Sudo attributes are available
-----------------------------

[](#sudo-attributes-are-available)

List of ***sudo*** attribute is given bellow.

```
a 		=	alt,
ac		=	action,
c 		=	class,
cls		=	class,
cont		=	content,
cs 		=	colspan,
d 		=	disabled,
dt 		=	datetime,
f 		=	for,
fa 		=	formaction,
h 		=	href,
i  		=	id,
ln 		=	lang,
m 		=	method,
mx 		=	max,
mn 		=	min,
mxlen		=	maxlength,
mnlen		=	minlength,
mt 		=	muted,
n  		=	name,
p  		=	placeholder,
pt		=	pattern,
r 		=	required,
rs 		=	rowspan,
rw 		=	rows,
s  		=	src,
sc		=	selected,
st		=	style,
t  		=	type,
v 		=	value,
val		=	value

```

Preset functionality
====================

[](#preset-functionality)

Tagger allows preset of ***attributes*** and ***wrapper***. It reduces using of same attribute and wrapping on same tag.

Preset attributes for identical tag
-----------------------------------

[](#preset-attributes-for-identical-tag)

Preset functionality works on common attribute value using ***set*** method. Here, preseting can be stoped by using ***stopSet*** method that accepts ***string*** or ***array*** of tag name or empty for destroy all.

```
Tag::set([
	'input' => [
		'c/cls/class' => 'form-control mt-2',
		...
	],
	'textarea' => '@input',		/* Same as input tag */
	...
]);

Tag::input(['type' => 'text']);
Tag::input(['type' => 'number']);
Tag::textarea(['b' => 'Text area', 'c' => 'text-danger']);

Tag::stopSet();
```

**Output:**

```

Text area
```

Preset wrapper for identical tag
--------------------------------

[](#preset-wrapper-for-identical-tag)

Similar with ***set*** wrapping functionality works on common wrapper value, using ***wrap*** method. Here also, tag wrapping can be stoped by using ***stopWrap*** method that accepts ***string*** or ***array*** of tag name or empty for destroy all.

```
Tag::wrap([
	'input' => ['div', ['c' => 'col-md-6', ...]],
	'textarea' => 'div',
	'select' => '@input'	/* Same as input tag */
	...
]);

Tag::input(['t' => 'text']);
Tag::textarea();
Tag::select(['b' => ['option' => ['one', 'two']]]);

Tag::stopWrap(['textarea']);	/* OR Tag::stopWrap('textarea'); */
Tag::textarea("Text area value");
```

**Output:**

```

		one
		two

Text area value
```

Special use
===========

[](#special-use)

Label
-----

[](#label)

Automatic `` *tag* can be added before any tag, using ***label*** attribute. If label containing tag has a wrapper preset, a label tag will be created into the wrapper before this.

```
Tag::wrap([
	'input' => ['div', ['c' => 'col-md-6 mb-2']]
]);

Tag::input(['t' => 'text', 'i' => 'name', 'label' => 'Name *', 'p' => "Name"]);
Tag::input(['t' => 'number', 'i' => 'age', 'label' => 'Age *', 'p' => "Age"]);
```

**Output**

```

	Name *

	Age *

```

Table
-----

[](#table)

Here, html table is able to be generated dynamically. Where, ***body*** can be passed an array with ***key*** as ***tag name*** and ***key value*** as normal ***array*** for tag body.

```
$arrs = [
	['id' => 24, 'name' => 'HTML'],
	['id' => 33, 'name' => 'CSS'],
	['id' => 49, 'name' => 'JAVASCRIP']
];

Tag::table(['border' => '1', 'b' => function() use($arrs) {
	Tag::tr(['b' => ['th' => ['#', 'ID', 'Name']]]);
	Tag::tr(['foreach' => $arrs, 'offset' => 'i'
		'b' => ['td' => ['@i', '@id', '@name']]
	]);
}]);
```

**Output**

```

	#IDName
	124HTML
	233CSS
	349JAVASCRIP

```

Control statement
-----------------

[](#control-statement)

Control statement acts as like normal ***foreach/if/elseif/else*** here. Control statement uses as attribute.

### foreach:

[](#foreach)

Act like normal foreach in php. Here, ***offset***, ***start*** respectively used for loop array/object offset, and from which value offset count will be started.

```
Tag::ul(['if' => $arrs, 'b' => function() use($arrs) {
	Tag::li([
		'foreach' => $arrs, 'offset' => 'i',
		'if' => '@id > 24',
		'v' => '@id', 'b' => '@i. @name'
	]);
}]);
```

**Output**

```

	1. CSS
	2. JAVASCRIP

```

@id -&gt; @{array key name}.
Able to capture in any attribute value.

**Special Attributes:**Attributes given bellow are useful only iff ***foreach*** attribute is present.

- **'if' =&gt; string**

    - Normal if condition. Ex: ***(@i &gt; 2 &amp;&amp; (@age == 50 || @name == 'HTML'))***.
    - Here, ***@i*** is offset, ***@name*** is array key.
    - Note: ***@name*** value is string type. So, comparing *string* value must be block quoted.
- **'then' =&gt; string|array**

    - This attribute works when ***'if'*** condition is valid.
    - ***String*** type value consideres as attribute value *true*. Multiple *string* can be considered as identical attribute that seperated with *comma* or *semicolon* or *dot* or *space* `, OR ; OR . OR \s+`.
    - Ex:
        - ***'then' =&gt; 'selected disabled'***
        - ***'then' =&gt; \['selected' =&gt; true, 'disabled' =&gt; true\]***
    - Here, ***array*** contains attribute set which will be changed after a valid ***if*** condition.
- **'offset' =&gt; string**

    - Contains loop array *offset variable name*.
    - In **logical expression**, considers to be ***started form 0*** and **in view** depends on ***start*** attribute.
- **'start' =&gt; int**

    - Denotes from where body/view offset will be started from. Default start value is **1**.

### if:

[](#if)

Normal ***if*** statement like php.
**Note:** Attribute ***then*** is allowed as same way of ***if*** statement in ***foreach*** *special attributes* section. But, only ***array*** type value is working here.

```
$var = 10;
Tag::span(['if' => $var > 10, 'b' => 'Var is greater than 10']);
```

**Normal use:**

```
if($var > 10)
	echo "Var is greater than 10
```

### elseif:

[](#elseif)

Normal ***elseif*** statement like php. Here, this condition will only work iff ***if*** statment is present before this.
**Note:** Attribute ***then*** is allowed as same way of ***if*** statement.

```
Tag::span(['elseif' => $var > 5, 'b' => 'Var is greater than 5']);
```

**Normal use:**

```
if ($var > 10)
	...
else if ($var > 5)
	echo "Var is greater than 5
```

### else:

[](#else)

Normal ***else*** statement like php. Value should be given as ***true***. Here, this condition will only work iff ***if*** or ***elseif*** statment is present before this.
**Note:** Attribute ***then*** is not allowed here.

```
Tag::span(['else' => true, 'b' => 'Var is less than 5']);
```

**Normal use:**

```
if ($var > 10)
	...
else
	echo "Var is less than 5
```

Authors
-------

[](#authors)

*Initially development* - ***Sadman Rafid***

License
-------

[](#license)

The tagger is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2115d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/57731032?v=4)[A. M. Sadman Rafid](/maintainers/amsrafid)[@amsrafid](https://github.com/amsrafid)

---

Top Contributors

[![amsrafid](https://avatars.githubusercontent.com/u/57731032?v=4)](https://github.com/amsrafid "amsrafid (63 commits)")

---

Tags

buildereasyhtmlphpplugintaggingtagsviewviewmodelhtmlviewtagmarkupattributetaggeramsrafid

### Embed Badge

![Health badge](/badges/amsrafid-tagger/health.svg)

```
[![Health](https://phpackages.com/badges/amsrafid-tagger/health.svg)](https://phpackages.com/packages/amsrafid-tagger)
```

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.5k34.7M186](/packages/phpoffice-phpword)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7526.3M230](/packages/laminas-laminas-view)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)[ogheo/yii2-htmlcompress

Compress HTML output into a single line

20184.4k1](/packages/ogheo-yii2-htmlcompress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
