Where to put a Global form renderer?

Notice: This thread is very old.
Member | 4

I know this must be a simple idiots question.

Where should I put some renderer code (and have it included) – so that it affects all rendered forms? overwriting the defaultform renderer.

The forms examples have everything in the one php file – which doesn't help me understand where in the MVP structure of Nette stuff like this should go in order to avoid duplication of code.

// setup form rendering
$renderer = $form->getRenderer();
$renderer->wrappers['controls']['container'] = NULL;
$renderer->wrappers['pair']['container'] = 'div class=form-group';
$renderer->wrappers['pair']['.error'] = 'has-error';
$renderer->wrappers['control']['container'] = 'div class=col-sm-9';
$renderer->wrappers['label']['container'] = 'div class="col-sm-3 control-label"';
$renderer->wrappers['control']['description'] = 'span class=help-block';
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
// make form and controls compatible with Twitter Bootstrap
foreach ($form->getControls() as $control) {
	$type = $control->getOption('type');
	if ($type === 'button') {
		$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
		$usedPrimary = TRUE;
	} elseif (in_array($type, ['text', 'textarea', 'select'], TRUE)) {
	} elseif (in_array($type, ['checkbox', 'radio'], TRUE)) {
Member | 3598

Make your own BaseForm which is set as you want.

Member | 648

Or use existing renderer (as a package). E.g. https://github.com/…otstrap-form

Last edited by newPOPE (2016-12-13 09:45)