Example #1
0
 /**
  * Calls one of the blocks in the template. It tries using a block
  * called <type>_<action>, and if that does not exist, falls back to field_<action>
  * @param  string             $action
  * @param  \snb\form\FormView $data
  * @return string
  */
 public function render($action, $data)
 {
     // make sure we got something
     if ($data == null) {
         return '';
     }
     // In fact, it must be a FormView...
     if (!$data instanceof FormView) {
         return '';
     }
     // Get to work, finding a suitable block to render the Form view with
     $blocks = $this->template->getBlocks();
     $type = $data->get('type', 'field');
     $typeAction = $type . '_' . $action;
     if (!array_key_exists($typeAction, $blocks)) {
         $typeAction = 'field_' . $action;
     }
     ob_start();
     $this->template->displayBlock($typeAction, $data->all(), $blocks);
     $html = ob_get_clean();
     return $html;
 }