mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
add custom tags
This commit is contained in:
parent
a9745c2f1c
commit
ec210f8b8e
|
|
@ -80,6 +80,14 @@ final class Head implements RenderableInterface
|
|||
*/
|
||||
private array $script = [];
|
||||
|
||||
/**
|
||||
* Tags bound to this page instance.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $tags = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
@ -91,7 +99,7 @@ final class Head implements RenderableInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Set page title.
|
||||
* Add asset.
|
||||
*
|
||||
* @param int $type Asset type
|
||||
* @param string $uri Asset uri
|
||||
|
|
@ -105,6 +113,21 @@ final class Head implements RenderableInterface
|
|||
$this->assets[$uri] = ['type' => $type, 'attributes' => $attributes];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tag.
|
||||
*
|
||||
* @param int $type Asset type
|
||||
* @param string $uri Asset uri
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addTag(string $tag, string $content, array $attributes = []) : void
|
||||
{
|
||||
$this->tags[] = ['tag' => $tag, 'content' => $content, 'attributes' => $attributes];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page language.
|
||||
*
|
||||
|
|
@ -296,4 +319,27 @@ final class Head implements RenderableInterface
|
|||
|
||||
return $rendered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tags.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderTags() : string
|
||||
{
|
||||
$rendered = '';
|
||||
foreach ($this->tags as $tag) {
|
||||
$rendered .= '<' . $tag['tag'];
|
||||
|
||||
foreach ($tag['attributes'] as $key => $attribute) {
|
||||
$rendered .= ' ' . $key . '="' . $attribute . '"';
|
||||
}
|
||||
|
||||
$rendered .= '>' . $tag['content'] . '</' . $tag['tag'] . '>';
|
||||
}
|
||||
|
||||
return $rendered;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user