Skip to content

Commit

Permalink
examples: updated latte templates
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 17, 2024
1 parent efad361 commit bbd8b8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions examples/latte/form-bootstrap5.latte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{* Generic form template for Bootstrap v5 *}

{parameters $name}
{define bootstrap-form, $name}
<form n:name=$name>
{* List for form-level error messages *}
<ul class="alert alert-danger" n:ifcontent>
Expand All @@ -14,9 +14,10 @@

{include controls $form->getControls()}
</form>
{/define}


{define controls array $controls}
{define local controls, array $controls}
{* Loop over form controls and render each one *}
<div n:foreach="$controls as $control"
n:if="!$control->getOption(rendered) && $control->getOption(type) !== hidden"
Expand All @@ -42,7 +43,7 @@
{/define}


{define control Nette\Forms\Controls\BaseControl $control}
{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}
Expand Down
5 changes: 3 additions & 2 deletions examples/latte/form.latte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{* Generic form template *}

{parameters $name}
{define form, $name}
<form n:name=$name>
{* List for form-level error messages *}
<ul class=error n:ifcontent>
Expand All @@ -14,9 +14,10 @@

{include controls $form->getControls()}
</form>
{/define}


{define controls array $controls}
{define local controls, array $controls}
{* Loop over form controls and render each one *}
<table>
<tr n:foreach="$controls as $control"
Expand Down
4 changes: 3 additions & 1 deletion examples/latte/page.latte
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{import 'form-bootstrap5.latte'}

<!DOCTYPE html>
<html>
<head>
Expand All @@ -11,7 +13,7 @@
<div class="container">
<h1>Nette Forms & Bootstrap v5 rendering example</h1>

{include form-bootstrap5.latte $form}
{include bootstrap-form, $form}
</div>
</body>
</html>

0 comments on commit bbd8b8c

Please sign in to comment.