Skip to content

Commit 62e9df4

Browse files
committed
Symfony default form template customized
1 parent fef2582 commit 62e9df4

File tree

7 files changed

+50
-20
lines changed

7 files changed

+50
-20
lines changed

config/packages/twig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
twig:
22
default_path: '%kernel.project_dir%/templates'
3+
form_themes: ['form/tailwind.html.twig']

postcss.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const purgecss = require('@fullhuman/postcss-purgecss')({
22

33
// Specify the paths to all of the template files in your project
44
content: [
5-
'./templates/**/*.html.twig',
5+
'./templates/**/*.twig',
66
],
77

88
// This is the function used to extract class names from your templates
@@ -15,12 +15,12 @@ const purgecss = require('@fullhuman/postcss-purgecss')({
1515

1616
return broadMatches.concat(innerMatches)
1717
}
18-
})
18+
});
1919

2020
module.exports = {
2121
plugins: [
2222
require('tailwindcss'),
2323
require('autoprefixer'),
2424
purgecss,
2525
]
26-
}
26+
};

templates/form/tailwind.html.twig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% use "form_div_layout.html.twig" %}
2+
3+
{# Widgets #}
4+
{%- block form_widget_simple -%}
5+
{%- set type = type|default('text') -%}
6+
{%- if type == 'range' or type == 'color' -%}
7+
{# Attribute "required" is not supported #}
8+
{%- set required = false -%}
9+
{%- endif -%}
10+
<input class="bg-gray-400 bg-placeholder-gray-300 border-gray-600 focus:bg-white w-full p-2 rounded" type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
11+
{%- endblock form_widget_simple -%}
12+
13+
{%- block form_row -%}
14+
{%- set widget_attr = {} -%}
15+
{%- if help is not empty -%}
16+
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
17+
{%- endif -%}
18+
<div class="m-3 pt-3" {% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
19+
{{- form_label(form) -}}
20+
{{- form_errors(form) -}}
21+
{{- form_widget(form, widget_attr) -}}
22+
{{- form_help(form) -}}
23+
</div>
24+
{%- endblock form_row -%}

templates/reset_password/check_email.html.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
{% block title %}Password Reset Email Sent{% endblock %}
44

55
{% block body %}
6-
<p>An email has been sent that contains a link that you can click to reset your password. This link will expire in {{ tokenLifetime|date('g') }} hour(s).</p>
7-
<p>If you don't receive an email please check your spam folder or <a href="{{ path('app_forgot_password_request') }}">try again</a>.</p>
6+
<p class="text-center">An email has been sent that contains a link that you can click to reset your password. This link will expire in {{ tokenLifetime|date('g') }} hour(s).</p>
7+
<p>If you don't receive an email please check your spam folder or
8+
<a class="font-bold" href="{{ path('app_forgot_password_request') }}">try again</a>.
9+
</p>
810
{% endblock %}

templates/reset_password/request.html.twig

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
{% block title %}Reset your password{% endblock %}
44

55
{% block body %}
6-
{% for flashError in app.flashes('reset_password_error') %}
7-
<div class="alert alert-danger" role="alert">{{ flashError }}</div>
8-
{% endfor %}
9-
<h1>Reset your password</h1>
6+
<div class="w-full md:w-1/2 mx-auto">
7+
{% for flashError in app.flashes('reset_password_error') %}
8+
<div class="bg-red-400 p-3" role="alert">{{ flashError }}</div>
9+
{% endfor %}
10+
<h1>Reset your password</h1>
1011

11-
{{ form_start(requestForm) }}
12+
{{ form_start(requestForm) }}
1213
{{ form_row(requestForm.email) }}
13-
<div>
14-
<small>
15-
Enter your email address and we we will send you a
16-
link to reset your password.
17-
</small>
18-
</div>
1914

20-
<button class="btn btn-primary">Send password reset email</button>
21-
{{ form_end(requestForm) }}
15+
<p class="p-4 m-3 text-gray-500">
16+
Enter your email address and we we will send you a
17+
link to reset your password.
18+
</p>
19+
<div class="text-center">
20+
<button class="bg-green-600 p-3 text-white">Send password reset email</button>
21+
{{ form_end(requestForm) }}
22+
</div>
23+
</div>
2224
{% endblock %}

templates/reset_password/reset.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
{{ form_start(resetForm) }}
99
{{ form_row(resetForm.plainPassword) }}
10-
<button class="btn btn-primary">Reset password</button>
10+
<button class="">Reset password</button>
1111
{{ form_end(resetForm) }}
1212
{% endblock %}

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ Encore
7373
//.enableReactPreset()
7474
//.addEntry('admin', './assets/js/admin.js')
7575
;
76+
7677
Encore.enablePostCssLoader(function(options) {
7778
options.config = {
7879
path: 'postcss.config.js'
7980
}
80-
})
81+
});
8182
module.exports = Encore.getWebpackConfig();

0 commit comments

Comments
 (0)