Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Fixes #100 - Missing documentation for Zend\View\Helper\HtmlTag
Browse files Browse the repository at this point in the history
  • Loading branch information
froschdesign committed Aug 5, 2019
1 parent 8bad7f9 commit ea23993
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
98 changes: 98 additions & 0 deletions doc/book/helpers/html-tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# HtmlTag

The `HtmlTag` helper is used to **create the root of a HTML document**, the open
and close tags for the `<html>` element.

## Basic Usage

```php
<?= $this->htmlTag(['lang' => 'en'])->openTag() ?>
<!-- Some HTML -->
<?= $this->htmlTag()->closeTag() ?>
```

Output:

```html
<html lang="en">
<!-- Some HTML -->
</html>
```

## Using Attributes

### Set a single Attribute

```php fct_label="Invoke Usage"
$this->htmlTag(['lang' => 'en']);

echo $this->htmlTag()->openTag(); // <html lang="en">
```

```php fct_label="Setter Usage"
$this->htmlTag()->setAttribute('lang', 'en');

echo $this->htmlTag()->openTag(); // <html lang="en">
```

### Set multiple Attributes

```php fct_label="Invoke Usage"
$this->htmlTag(['lang' => 'en', 'id' => 'example']);

echo $this->htmlTag()->openTag(); // <html lang="en" id="example">
```

```php fct_label="Setter Usage"
$this->htmlTag()->setAttributes(['lang' => 'en', 'id' => 'example']);

echo $this->htmlTag()->openTag(); // <html lang="en" id="example">
```

### Get current Value

To get the current value, use the `getAttributes()` method.

```php
$this->htmlTag(['lang' => 'en', 'id' => 'example']);

var_dump($this->htmlTag()->getAttributes()); // ['lang' => 'en', 'id' => 'example']
```

### Default Value

The default value is an empty `array` that means no attributes are set.

## Using Namespace

The `HtmlTag` helper can automatically add the [XHTML namespace](http://www.w3.org/1999/xhtml/)
for XHTML documents. To use this functionality, the [`Doctype` helper](doctype.md)
is used.

The namespace is added only if the document type is set to an XHTML type and use
is enabled:

```php
// Set doctype to XHTML
$this->doctype(Zend\View\Helper\Doctype::XHTML1_STRICT);

// Add namespace to open tag
$this->htmlTag()->setUseNamespaces(true);

// Output
echo $this->htmlTag()->openTag(); // <html xmlns="http://www.w3.org/1999/xhtml">
```

### Get current Value

To get the current value, use the `getUseNamespaces()` method.

```php
$this->htmlTag()->setUseNamespaces(true);

var_dump($this->htmlTag()->getUseNamespaces()); // true
```

### Default Value

The default value is `false` that means no namespace is added as attribute.
1 change: 1 addition & 0 deletions doc/book/helpers/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ for, and rendering, the various HTML `<head>` tags, such as `HeadTitle`,
- [HeadTitle](head-title.md)
- [HtmlList](html-list.md)
- [HTML Object Plugins](html-object.md)
- [HtmlTag](html-tag.md)
- [Identity](identity.md)
- [InlineScript](inline-script.md)
- [JSON](json.md)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pages:
- HeadTitle: helpers/head-title.md
- HtmlList: helpers/html-list.md
- HtmlObject: helpers/html-object.md
- HtmlTag: helpers/html-tag.md
- Identity: helpers/identity.md
- InlineScript: helpers/inline-script.md
- Json: helpers/json.md
Expand Down

0 comments on commit ea23993

Please sign in to comment.