This namespace contains components that help with the generation of HTML.
The Phalcon\Html\Attributes is a wrapper of Phalcon\Collection. It also contains two more methods render() and __toString(). render() uses Phalcon\Tag internally to render the attributes that a HTML element has. These HTML attributes are defined in the object itself.
The component can be used on its own if you want to collect HTML attributes in an object and then _render) them (return them as a string) in a key=value format.
This component is used internally by Phalcon\Forms\Form to store the attributes of form elements.
A common piece of HTML that is present in many web applications is the breadcumbs. These are links separated by a space or by the / character usually, that represent the tree structure of an application. The purpose is to give users another easy visual way to navigate throughout the application.
An example is an application that has an admin module, an invoices area and a view invoice page. Usually, you would select the the admin module, then from the links you will choose invoices (list) and then clicking on one of the invoices in the list, you can view it. To represent this tree like structure, the breadcrumbs displayed could be:
Each of the words above (apart from the last one) are links to the respective pages. This way the user can quickly navigate back to a different area without having to click the back button or use another menu.
Phalcon\Html\Breadcrumbs offers functionality to add text and URLs. The resulting HTML when calling render() will have each breadcrumb enclosed in <dt> tags, while the whole string is enclosed in <dl> tags.
The last set crumb will not have a link and will only have its text displayed. Each crumb is wrapped in <dt></dt> tags. The whole collection is wrapped in <dl></dl> tags. You can use them in conjunction with CSS to format the crumbs on screen according to the needs of your application.
public function setSeparator(string $separator)
The default separator between the crumbs is /. You can set a different one if you wish using this method.
Returns the internal breadcrumbs array
Phalcon\Html\TagFactory is a component that generates HTML tags. This component creates a new class locator with predefined HTML tag classes attached to it. Each tag class is lazy loaded for maximum performance. To instantiate the factory and retrieve a tag helper, you need to call newInstance().
All helpers that are used by the Phalcon\Html\TagFactory are located under the Phalcon\Html\Helper namespace. You can create each of these classes individually if you wish to, or you can use the tag factory as shown above. Other than the *Raw helpers, if text is required by the helper, it will be automatically escaped using Phalcon\Escaper.
NOTE: The code and output below has been formatted for readability
Phalcon\Html\Helper\Anchor creates anchor HTML tags. The component accepts the href as a string, the text as a string and optionally an array with all the attributes that the anchor needs.
Phalcon\Html\Helper\AchorRaw creates raw anchor HTML tags, i.e. the text will not be escaped. The component accepts the href as a string, the text as a string and optionally an array with all the attributes that the anchor needs.
Phalcon\Html\Helper\Element creates HTML tags based on the passed name parameter. The component accepts the name as a string, the text as a string and optionally an array with all the attributes that the anchor needs.
Phalcon\Html\Helper\ElementRaw creates raw HTML tags, i.e. the text will not be escaped. The tag created is based on the passed name parameter. The component accepts the name as a string, the text as a string and optionally an array with all the attributes that the anchor needs.
Phalcon\Html\Helper\Form creates <form> HTML tags. The component accepts an array with all the attributes that the anchor needs. By default the form has its method to post and enctype to multipart/form-data.