Last active
March 22, 2023 22:57
-
-
Save YannickFricke/efd8fbf34c36627623000a363c039f40 to your computer and use it in GitHub Desktop.
Form theme for symfony for semantic ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- block form_start -%} | |
{%- do form.setMethodRendered() -%} | |
{% set method = method|upper %} | |
{%- if method in ["GET", "POST"] -%} | |
{% set form_method = method %} | |
{%- else -%} | |
{% set form_method = "POST" %} | |
{%- endif -%} | |
{% if attr.class is defined %} | |
{% if 'ui' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' ui')|trim}) %} | |
{% endif %} | |
{% if 'form' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' form')|trim}) %} | |
{% endif %} | |
{% else %} | |
{% set attr = attr|merge({'class': 'ui form'}) %} | |
{% endif %} | |
<form name="{{ name }}" method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}> | |
{%- if form_method != method -%} | |
<input type="hidden" name="_method" value="{{ method }}" /> | |
{%- endif -%} | |
{%- endblock form_start -%} | |
{% block form_row %} | |
<div class="field"> | |
{{- form_label(form) -}} | |
{{- form_errors(form) -}} | |
{{- form_widget(form) -}} | |
</div> | |
{% endblock %} | |
{%- block button_row -%} | |
{{- form_widget(form) -}} | |
{%- endblock button_row -%} | |
{% block submit_widget %} | |
{%- if label is empty -%} | |
{%- if label_format is not empty -%} | |
{% set label = label_format|replace({ | |
'%name%': name, | |
'%id%': id, | |
}) %} | |
{%- else -%} | |
{% set label = name|humanize %} | |
{%- endif -%} | |
{%- endif -%} | |
{% if attr.class is defined %} | |
{% if 'ui' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' ui')|trim}) %} | |
{% endif %} | |
{% if 'primary' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' primary')|trim}) %} | |
{% endif %} | |
{% if 'button' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' button')|trim}) %} | |
{% endif %} | |
{% else %} | |
{% set attr = attr|merge({'class': 'ui primary button'}) %} | |
{% endif %} | |
<button type="{{ type|default('submit') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</button> | |
{% endblock %} | |
{% block reset_widget %} | |
{%- if label is empty -%} | |
{%- if label_format is not empty -%} | |
{% set label = label_format|replace({ | |
'%name%': name, | |
'%id%': id, | |
}) %} | |
{%- else -%} | |
{% set label = name|humanize %} | |
{%- endif -%} | |
{%- endif -%} | |
{% if attr.class is defined %} | |
{% if 'ui' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' ui')|trim}) %} | |
{% endif %} | |
{% if 'primary' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' negative')|trim}) %} | |
{% endif %} | |
{% if 'button' not in attr.class %} | |
{% set attr = attr|merge({'class': (attr.class ~ ' button')|trim}) %} | |
{% endif %} | |
{% else %} | |
{% set attr = attr|merge({'class': 'ui negative button'}) %} | |
{% endif %} | |
<button type="{{ type|default('reset') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</button> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment