holantomas/Semantic
, (*1)
This extension is here to provide HTML Document api for Nette Framework., (*2)
Installation
Composer package is not prepared yet, (*3)
The best way to install is using Composer:, (*4)
$ composer require holantomas/semantic
Register extension in neon config, (*5)
extensions:
semantic: holantomas\Semantic\Bridges\Nette\SemanticExtension
You can setup your own IDocument implementation., (*6)
semantic:
document: namespace\to\your\document # Or false to disble it
If you have your implementation of IDocument you have to specify @required annotation for document properties which will cause warnings when are empty or NULL. You don't have to care about properties visibility, (*7)
use holantomas\Semantic\IDocument;
class MyDocument implements IDocument {
/**
* @var string
* @required - this make property required (throws warnings)
*/
private $title = '';
}
Enable Tracy panel(optional) - if is Tracy panel disabled, document throws E_USER_WARNING after render on @required properties which are NULL or empty, (*8)
tracy:
bar:
- holantomas\Semantic\Bridges\Tracy\SemanticPanel
For show properties in panel you have to specify @panel on every property., (*9)
use holantomas\Semantic\IDocument;
class MyDocument implements IDocument {
/**
* @var string
* @required - this make property required (throws warnings)
* @panel - this make property show in tracy panel
*/
private $title = '';
}
annotations can be customized by Checker::$REQUIREMENT_ANNOTATION and SemanticPanel::$RENDER_ANNOTATION, (*10)
Usage
Document is automaticly registered as service and insert to presenter template param named as document.
You don't have to do $this->template->document = $this->document; in presenter., (*11)
namespace App;
use Nette\Application\UI\Presenter;
use holantomas\Semantic\IDocument;
class BasePresenter extends Presenter
{
/** @var IDocument @inject */
public $document;
}
class ExamplePresenter extends BasePresenter
{
public function actionDefault(){
$this->document->setTitle('Hello world!');
}
}
<html>
<head>
<title>{$document->getTitle()}</title>
...
</head>
...
</html>
Of course you can autowire document to all services or components and modify properties., (*12)
Open graph and tests coming soon, (*13)