The <meta> HTML element represents metadata that cannot be represented by other HTML meta-related elements, like
<base>, <link>, <script>, <style>, or <title>.
Instantiate the Meta class using Meta::widget().
$meta = Meta::widget();Use the provided methods to set specific attributes for the a element.
// setting class attribute
$meta->class('external');Or, use the attributes method to set multiple attributes at once.
$meta->attributes(['class' => 'external', 'id' => 'MyId']);If you want to include content within the meta tag, use the content and name methods.
$meta->content('value')->name('csfr');If you want to include http-equiv within the meta tag, use the httpEquiv y content methods.
$meta->httpEquiv('refresh')->content('30');Generate the HTML output using the render method.
$html = $meta->render();Or, use the magic __toString method.
$html = (string) $meta;Below are examples of common use cases:
// adding multiple attributes
$meta->class('external')->name('viewport')->content('width=device-width, initial-scale=1');Explore additional methods for setting various attributes such as content, httpEquiv, id, name, lang and more.
Refer to the Attribute Tests for comprehensive examples.
The following methods are available for setting attributes:
| Method | Description |
|---|---|
attributes() |
Set multiple attributes at once. |
charset() |
Set the charset attribute. |
class() |
Set the class attribute. |
content() |
Set the content within the meta element. |
httpEquiv() |
Set the http-equiv attribute. |
id() |
Set the id attribute. |
lang() |
Set the lang attribute. |
name() |
Set the name attribute. |
style() |
Set the style attribute. |
Refer to the Custom Method Test for comprehensive examples.
The following methods are available for customizing the HTML output:
| Method | Description |
|---|---|
render() |
Generates the HTML output. |
widget() |
Instantiates the Meta::class. |