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

Commit 509fc2e

Browse files
committed
Merge pull request #98 from wandersonwhcr/meta-charset-position
Render HTML5 meta charset at first position
2 parents 8a1f196 + 407a451 commit 509fc2e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Helper/HeadMeta.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,18 @@ public function toString($indent = null)
176176
$items = [];
177177
$this->getContainer()->ksort();
178178

179+
$isHtml5 = $this->view->plugin('doctype')->isHtml5();
180+
179181
try {
180182
foreach ($this as $item) {
181-
$items[] = $this->itemToString($item);
183+
$content = $this->itemToString($item);
184+
185+
if ($isHtml5 && $item->type == 'charset') {
186+
array_unshift($items, $content);
187+
continue;
188+
}
189+
190+
$items[] = $content;
182191
}
183192
} catch (Exception\InvalidArgumentException $e) {
184193
trigger_error($e->getMessage(), E_USER_WARNING);

test/Helper/HeadMetaTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,21 @@ public function testCharset()
422422
);
423423
}
424424

425+
public function testCharsetPosition()
426+
{
427+
$view = new View();
428+
$view->plugin('doctype')->__invoke('HTML5');
429+
430+
$view->plugin('headMeta')
431+
->setProperty('description', 'foobar')
432+
->setCharset('utf-8');
433+
434+
$this->assertEquals(
435+
'<meta charset="utf-8">' . PHP_EOL
436+
. '<meta property="description" content="foobar">',
437+
$view->plugin('headMeta')->toString());
438+
}
439+
425440
/**
426441
* @group ZF-9743
427442
*/

0 commit comments

Comments
 (0)