nepada/meta-control

Nette control for managing meta data in HTML header.

v1.5.1 2024-10-27 17:04 UTC

README

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/meta-control

Usage

First register the control factory in your config and optionally set up default metadata:

services:
    -
        implement: Nepada\MetaControl\MetaControlFactory
        setup:
            - setCharset('utf-8')
            - setAuthor('Jon Doe')

Use the control factory in your presenter:

protected function createComponentMeta(): Nepada\MetaControl\MetaControl
{
    $control = $this->metaControlFactory->create();
    $control->setDescription('Lorem ipsum');
    return $control;
}

And render it in your Latte template:

<html>
<head>
    {control meta}
</head>
<body>
    ...
</body>
</html>

Overview of supported meta tags

Charset:

// <meta charset="utf-8">
$control->setCharset('utf-8');
$control->getCharset(); // 'utf-8'

Document metadata:

// <meta name="author" content="John Doe">
$control->setMetadata('author', 'Jon Doe');
$control->getMetadata('author'); // 'Jon Doe'

Document properties:

// <meta property="og:title" content="Foo title">
$control->setProperty('og:title', 'Foo title');
$control->getProperty('og:title'); // 'Foo title'

Pragma directives:

// <meta http-equiv="content-type" content="text/html; charset=UTF-8">
$control->setPragma('content-type', 'text/html; charset=UTF-8');
$control->getPragma('content-type'); // 'text/html; charset=UTF-8'

Shorthands for standard metadata

Author:

// <meta name="author" content="John Doe">
$control->setAuthor('Jon Doe');
$control->getAuthor(); // 'Jon Doe'

Description:

// <meta name="description" content="Lorem ipsum">
$control->setDescription('Lorem ipsum');
$control->getDescription(); // 'Lorem ipsum'

Keywords:

// <meta name="keywords" content="foo, bar, baz">
$control->setKeywords('foo', 'bar');
$control->addKeyword('baz');
$control->getKeywords(); // ['foo', 'bar', 'baz']

Robots:

// <meta name="robots" content="noindex, nofollow">
$control->setRobots('noindex, nofollow');
$control->getRobots(); // 'noindex, nofollow'