zenify/title-component

Title component for Nette

Installs: 720

Dependents: 0

Stars: 3

Watchers: 2

Forks: 2

Language: PHP

v5.0.1 2015-03-12 09:31 UTC

README

Build Status Quality Score Code Coverage Downloads this Month Latest stable

Install

Via Composer:

$ composer require zenify/title-component

Register extension in config.neon:

extensions:
    - Zenify\TitleComponent\DI\TitleExtension

Usage

Inject to presenter

class Presenter ...
{

    /**
     * @inject
     * @var Zenify\TitleComponent\TitleControlFactory
     */
    public $titleControlFactory;


    /**
     * @return Zenify\TitleComponent\TitleControl
     */
    protected function createComponentTitle()
    {
        return $this->titleControlFactory->create();
    }

}

Render in template

<head>
    ...
    {control title}
</head>

Add title

Via annotation

class HomepagePresenter ...
{

    /**
     * @title Contact us
     */
    public function renderContact()
    {
    }

}

Or via method

class ProductPresenter ...
{

    public function startup()
    {
        // set main title for whole app
        $this['title']->set('Zenify');
        parent::startup();
    }


    /**
     * @param int
     */
    public function renderDetail($id)
    {
        $product = ...($id);
        $this['title']->append('Detail of ' . $product->name);

        // change separator if you like
        $this['title']->setSeparator(' - ');
    }

}

This will result in:

Zenify - Detail of product ...

Translator supported

class HomepagePresenter ...
{

    /**
     * @title homepage.contact.title
     */
    public function renderContact()
    {
    }


    /**
     * @param string
     */
    public function renderDetail($name)
    {
        $this['title']->set(['user.detail.name', NULL, ['name' => $name]]);
    }

}