Skip to content
This repository was archived by the owner on Apr 7, 2019. It is now read-only.

Commit d80e429

Browse files
committed
adding form input macro
1 parent e350a71 commit d80e429

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

dist/_macros/forms.twig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% macro input(name, type, classes, label, placeholder, value, size, required) %}
2+
{% set show_label = label|default(true) %}
3+
<div class="field-container {{ classes }}">
4+
{% if show_label %}
5+
<label class="{{ classes }}">{{ label|default(name|title) }}{% if required %}<abbr title="Required">*</abbr>{% endif %}
6+
{% endif %}
7+
<input type="{{ type|default('text') }}" name="{{ name }}" placeholder="{{ placeholder|default(name|title) }}" value="{{ value|e }}" size="{{ size|default(20) }}"{% if required %} required{% endif %} />
8+
{% if show_label %}</label>{% endif %}
9+
</div>
10+
{% endmacro %}
11+
12+
{% macro textarea(label, placeholder, rows, classes) %}
13+
{% set show_label = label|default(true) %}
14+
<div class="field-container {{ classes }}">
15+
{% if show_label %}
16+
<label class="{{ classes }}">{{ label|default(name|title) }}{% if required %}<abbr title="Required">*</abbr>{% endif %}
17+
{% endif %}
18+
<textarea placeholder="{{ placeholder|default(name|title) }}" rows="{{ rows|default(8) }}"{% if required %} required{% endif %}></textarea>
19+
{% if show_label %}</label>{% endif %}
20+
</div>
21+
{% endmacro %}
Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
1+
{% import "forms.twig" as forms %}
12
<fieldset>
2-
<div class="field-container">
3-
<label for="text">Text Input <abbr title="Required">*</abbr></label>
4-
<input id="text" type="text" placeholder="Text Input">
5-
</div>
6-
<div class="field-container">
7-
<label for="password">Password</label>
8-
<input id="password" type="password" placeholder="Type your Password">
9-
</div>
10-
<div class="field-container">
11-
<label for="webaddress">Web Address</label>
12-
<input id="webaddress" type="url" placeholder="http://yoursite.com">
13-
</div>
14-
<div class="field-container">
15-
<label for="emailaddress">Email Address</label>
16-
<input id="emailaddress" type="email" placeholder="[email protected]">
17-
</div>
18-
<div class="field-container">
19-
<label for="search">Search</label>
20-
<input id="search" type="search" placeholder="Enter Search Term">
21-
</div>
22-
<div class="field-container">
23-
<label for="text">Number Input <abbr title="Required">*</abbr></label>
24-
<input id="text" type="number" placeholder="Enter a Number" pattern="[0-9]*">
25-
</div>
26-
<div class="field-container">
27-
<label for="textarea">Textarea</label>
28-
<textarea id="textarea" rows="8" cols="48" placeholder="Enter your message here"></textarea>
29-
</div>
30-
<div class="field-container">
31-
<label class="error">Error Input</label>
32-
<input class="is-error" type="text" placeholder="Text Input">
33-
</div>
34-
<div class="field-container">
35-
<label class="valid">Valid</label>
36-
<input class="is-valid" type="text" placeholder="Text Input">
37-
</div>
38-
</fieldset>
3+
{{ forms.input('Text Input') }}
4+
{{ forms.input('Password', 'password') }}
5+
{{ forms.input('Web Address', 'url') }}
6+
{{ forms.input('Email', 'email') }}
7+
{{ forms.input('Search', 'search') }}
8+
{{ forms.input('Number', 'number') }}
9+
{{ forms.input('Number', 'number') }}
10+
{{ forms.textarea('Textarea', 'Enter your message here') }}
11+
{{ forms.input('Error Input', 'text', 'error') }}
12+
{{ forms.input('Valid Input', 'text', 'valid') }}
13+
</fieldset>

0 commit comments

Comments
 (0)