From ea2399347508c36269c2691076c511ea97108da7 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 5 Aug 2019 23:33:22 +0200 Subject: [PATCH] Fixes #100 - Missing documentation for Zend\View\Helper\HtmlTag --- doc/book/helpers/html-tag.md | 98 ++++++++++++++++++++++++++++++++++++ doc/book/helpers/intro.md | 1 + mkdocs.yml | 1 + 3 files changed, 100 insertions(+) create mode 100644 doc/book/helpers/html-tag.md diff --git a/doc/book/helpers/html-tag.md b/doc/book/helpers/html-tag.md new file mode 100644 index 00000000..be9d0029 --- /dev/null +++ b/doc/book/helpers/html-tag.md @@ -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 `` element. + +## Basic Usage + +```php +htmlTag(['lang' => 'en'])->openTag() ?> + +htmlTag()->closeTag() ?> +``` + +Output: + +```html + + + +``` + +## Using Attributes + +### Set a single Attribute + +```php fct_label="Invoke Usage" +$this->htmlTag(['lang' => 'en']); + +echo $this->htmlTag()->openTag(); // +``` + +```php fct_label="Setter Usage" +$this->htmlTag()->setAttribute('lang', 'en'); + +echo $this->htmlTag()->openTag(); // +``` + +### Set multiple Attributes + +```php fct_label="Invoke Usage" +$this->htmlTag(['lang' => 'en', 'id' => 'example']); + +echo $this->htmlTag()->openTag(); // +``` + +```php fct_label="Setter Usage" +$this->htmlTag()->setAttributes(['lang' => 'en', 'id' => 'example']); + +echo $this->htmlTag()->openTag(); // +``` + +### 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(); // +``` + +### 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. diff --git a/doc/book/helpers/intro.md b/doc/book/helpers/intro.md index 8b476d6a..bfa6d8bd 100644 --- a/doc/book/helpers/intro.md +++ b/doc/book/helpers/intro.md @@ -68,6 +68,7 @@ for, and rendering, the various HTML `` 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) diff --git a/mkdocs.yml b/mkdocs.yml index fd188f24..af084a3d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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