{* Generic form template for Bootstrap v5 *} {define bootstrap-form, $name}
{* List for form-level error messages *}
{include controls $group->getControls()}
{include controls $form->getControls()}
{/define} {define local controls, array $controls} {* Loop over form controls and render each one *}
{* Label for the control *}
{label $control /}
{include control $control} {if $control->getOption(type) === button} {while $iterator->nextValue?->getOption(type) === button} {input $iterator->nextValue class => "btn btn-secondary"} {do $iterator->next()} {/while} {/if} {* Display control-level errors or descriptions, if present *} {$control->error} {$control->getOption(description)}
{/define} {define local control, Nette\Forms\Controls\BaseControl $control} {* Conditionally render controls based on their type with appropriate Bootstrap classes *} {if $control->getOption(type) in [text, select, textarea, datetime, file]} {input $control class => form-control} {elseif $control->getOption(type) === button} {input $control class => "btn btn-primary"} {elseif $control->getOption(type) in [checkbox, radio]} {var $items = $control instanceof Nette\Forms\Controls\Checkbox ? [''] : $control->getItems()}
{input $control:$key class => form-check-input}{label $control:$key class => form-check-label /}
{elseif $control->getOption(type) === color} {input $control class => "form-control form-control-color"} {else} {input $control} {/if} {/define}