Nette\Bridges\FormsLatte\FormMacros::install PHP Method

install() public static method

public static install ( Compiler $compiler )
$compiler Latte\Compiler
    public static function install(Latte\Compiler $compiler)
    {
        $me = new static($compiler);
        $me->addMacro('form', [$me, 'macroForm'], 'echo Nette\\Bridges\\FormsLatte\\Runtime::renderFormEnd(array_pop($this->global->formsStack));');
        $me->addMacro('formContainer', [$me, 'macroFormContainer'], 'array_pop($this->global->formsStack); $formContainer = $_form = end($this->global->formsStack)');
        $me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd'], NULL, self::AUTO_EMPTY);
        $me->addMacro('input', [$me, 'macroInput']);
        $me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']);
        $me->addMacro('inputError', [$me, 'macroInputError']);
    }

Usage Example

コード例 #1
0
 /**
  * @return Template
  */
 public function createTemplate(UI\Control $control = NULL)
 {
     $latte = $this->latteFactory->create();
     $template = new Template($latte);
     $presenter = $control ? $control->getPresenter(FALSE) : NULL;
     if ($control instanceof UI\Presenter) {
         $latte->setLoader(new Loader($control));
     }
     if ($latte->onCompile instanceof \Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) use($control, $template) {
         $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) {
             Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
         }
         if ($control) {
             $control->templatePrepareFilters($template);
         }
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (['normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse'] as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $latte->addFilter('null', function () {
     });
     $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
         return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit);
         // intentionally ==
     });
     if (!isset($latte->getFilters()['translate'])) {
         $latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi) {
             throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().');
         });
     }
     // default parameters
     $template->user = $this->user;
     $template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
     $template->flashes = [];
     if ($control) {
         $template->control = $control;
         $template->presenter = $presenter;
         $latte->addProvider('uiControl', $control);
         $latte->addProvider('uiPresenter', $presenter);
         $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($control));
     }
     $latte->addProvider('cacheStorage', $this->cacheStorage);
     // back compatibility
     $template->_control = $control;
     $template->_presenter = $presenter;
     $template->netteCacheStorage = $this->cacheStorage;
     if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
         $id = $control->getParameterId('flash');
         $template->flashes = (array) $presenter->getFlashSession()->{$id};
     }
     return $template;
 }
All Usage Examples Of Nette\Bridges\FormsLatte\FormMacros::install