/**
  * Render the templates.
  * @param Form    $form
  * @param string  $mode
  * @param array   $args
  */
 public function render(Form $form, $mode = NULL, $args = NULL)
 {
     if ($this->template === NULL) {
         if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
             /** @var \Nette\Application\UI\Presenter $presenter */
             $this->template = clone $presenter->getTemplate();
         } else {
             $this->template = new FileTemplate();
             $this->template->registerFilter(new \Nette\Latte\Engine());
         }
     }
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholdersĀ & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
             //$formEl->addClass('form-horizontal');
         }
     } elseif ($mode === 'begin') {
         foreach ($this->form->getControls() as $control) {
             /** @var \Nette\Forms\Controls\BaseControl $control */
             $control->setOption('rendered', FALSE);
         }
     }
     $this->template->setFile(__DIR__ . '/@form.latte');
     $this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
     if ($mode === NULL) {
         if ($args) {
             $this->form->getElementPrototype()->addAttributes($args);
         }
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, (array) $args);
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $attrs = array('input' => array(), 'label' => array());
         foreach ((array) $args as $key => $val) {
             if (stripos($key, 'input-') === 0) {
                 $attrs['input'][substr($key, 6)] = $val;
             } elseif (stripos($key, 'label-') === 0) {
                 $attrs['label'][substr($key, 6)] = $val;
             }
         }
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->attrs = (array) $attrs;
         $this->template->render();
     }
 }