Skip to content

Commit b78fa5e

Browse files
committed
updating docs
1 parent 7d7a1b0 commit b78fa5e

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

docs/html-tagfactory.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The registered names for respective helpers are:
4040
| `doctype` | `Phalcon\Html\Helper\Doctype` |
4141
| `element` | `Phalcon\Html\Helper\Element` |
4242
| `form` | `Phalcon\Html\Helper\Form` |
43+
| `friendlyTitle` | `Phalcon\Html\Helper\FriendlyTitle` |
4344
| `img` | `Phalcon\Html\Helper\Img` |
4445
| `inputCheckbox` | `Phalcon\Html\Helper\Input\Checkbox` |
4546
| `inputColor` | `Phalcon\Html\Helper\Input\Color` |
@@ -69,6 +70,7 @@ The registered names for respective helpers are:
6970
| `link` | `Phalcon\Html\Helper\Link` |
7071
| `meta` | `Phalcon\Html\Helper\Meta` |
7172
| `ol` | `Phalcon\Html\Helper\Ol` |
73+
| `preload` | `Phalcon\Html\Helper\Preload` |
7274
| `script` | `Phalcon\Html\Helper\Script` |
7375
| `style` | `Phalcon\Html\Helper\Style` |
7476
| `title` | `Phalcon\Html\Helper\Title` |
@@ -913,6 +915,44 @@ echo $helper($options);
913915

914916
This helper creates only the opening `<form>` tag. You will need to use the `Close` helper to generate the closing `</form>` tag.
915917

918+
### `friendlyTitle`
919+
[Phalcon\Html\Helper\FriendlyTitle][html-helper-friendlytitle] converts text to a URL-friendly slug.
920+
921+
| Parameter | Description |
922+
|----------------------------------|--------------------------------------------|
923+
| `string $text` | The text to convert |
924+
| `string $separator = '-'` | The separator character |
925+
| `bool $lowercase = true` | Convert the result to lowercase |
926+
| `array\|string $replace = []` | Characters/strings to replace with a space |
927+
928+
```php
929+
<?php
930+
931+
use Phalcon\Html\Escaper;
932+
use Phalcon\Html\Helper\FriendlyTitle;
933+
934+
$escaper = new Escaper();
935+
$helper = new FriendlyTitle($escaper);
936+
937+
echo $helper('Hello World');
938+
// hello-world
939+
940+
echo $helper('Hello World', '_');
941+
// hello_world
942+
943+
echo $helper('Hello World', '-', false);
944+
// Hello-World
945+
946+
echo $helper('Hello & World');
947+
// hello-and-world
948+
949+
echo $helper('Héllo Wörld');
950+
// hello-world
951+
952+
echo $helper('Hello/World', '-', true, ['/']);
953+
// hello-world
954+
```
955+
916956
### `img`
917957
[Phalcon\Html\Helper\Img][html-helper-img] creates a `<img>` tag.
918958

@@ -1955,6 +1995,51 @@ echo $result;
19551995
// </ol>
19561996
```
19571997

1998+
### `preload`
1999+
[Phalcon\Html\Helper\Preload][html-helper-preload] creates a `<link rel="preload">` tag for resource hinting. If a `ResponseInterface` is injected into `TagFactory`, it also sets the HTTP `Link:` header.
2000+
2001+
| Parameter | Description |
2002+
|--------------------------|----------------------------------------------------------------------|
2003+
| `string $href` | The resource URL |
2004+
| `string $type = 'style'` | The `as` attribute value (`style`, `script`, `font`, `image`, etc.) |
2005+
| `array $attributes = []` | Additional attributes (key/value) |
2006+
2007+
```php
2008+
<?php
2009+
2010+
use Phalcon\Html\Escaper;
2011+
use Phalcon\Html\Helper\Preload;
2012+
2013+
$escaper = new Escaper();
2014+
$helper = new Preload($escaper);
2015+
2016+
echo $helper('/my-style.css');
2017+
// <link rel="preload" href="/my-style.css" as="style" />
2018+
2019+
echo $helper('/my-script.js', 'script');
2020+
// <link rel="preload" href="/my-script.js" as="script" />
2021+
2022+
echo $helper('/my-font.woff2', 'font', ['crossorigin' => 'anonymous']);
2023+
// <link rel="preload" href="/my-font.woff2" as="font" crossorigin="anonymous" />
2024+
```
2025+
2026+
To also set the HTTP `Link:` response header (for HTTP/2 server push), pass a `ResponseInterface` as the third argument to `TagFactory`:
2027+
2028+
```php
2029+
<?php
2030+
2031+
use Phalcon\Html\Escaper;
2032+
use Phalcon\Html\TagFactory;
2033+
2034+
$escaper = new Escaper();
2035+
$response = $container->get('response');
2036+
$factory = new TagFactory($escaper, [], $response);
2037+
2038+
echo $factory->preload('/my-font.woff2', 'font');
2039+
// <link rel="preload" href="/my-font.woff2" as="font" />
2040+
// Also sets header: Link: </my-font.woff2>; rel="preload"; as="font"
2041+
```
2042+
19582043
### `script`
19592044
[Phalcon\Html\Helper\Script][html-helper-script] creates a `<script>` tag.
19602045

0 commit comments

Comments
 (0)