Я хочу иметь одинаковый внешний вид для всех таблиц и не устанавливать его каждый раз. Мое мнение:Как настроить стиль для всех таблиц в symfony 3 Bootstrap 3/4 twig
{% extends 'MyBundle::base.html.twig' %}
{% block pageTitle %}
Info Table {{ parent() }}
{% endblock %}
{% block pageContainer %}
<h1>My Info Table</h1>
<table class="table table-bordered table-striped table-hover">
<thead class="thead-inverse">
<tr>
<th>id</th>
<th>Name </th>
<th>parentid</th>
</tr>
</thead>
<tbody>
{% for entry in rows %}
<tr>
<td>{{ entry.id }}</td>
<td>{{ entry.productName }} ❏ {{ entry.sortName }}</td>
<td>{{ entry.parentId }}</td>
</tr>
{% else %}
<tr>
<td colspan="3">You don't have this!</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
бутстрапом определил в 'MyBundle :: base.html.twig'
<!DOCTYPE html>
<html lang="EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% spaceless %}{% block pageTitle %} - TEST {% endblock %}{% endspaceless %}</title>
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('assets/css/bootstrap.min.css') }}"/>
<link rel="stylesheet" href="{{ asset('assets/css/main.css') }}"/>
{% endblock %}
<link rel="shortcut icon" href="{{ asset('dtf-3.ico') }}"/>
</head>
<body>
{% block header %}
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<a class="btn btn-sm btn-primary" href="{{ path('MY_home') }}">TEST_menu</a>
<a class="btn btn-sm btn-info" href="{{ path('TEST_infoTable') }}">Info Table</a>
</div>
</div>
{% endblock %}
{% for flashMessage in app.session.flashBag.get('msg') %}
<div> {{ flashMessage }}</div>
{% endfor %}
{% block pageContainer %}{% endblock %}
{% block javascripts %}
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap-datepicker.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
{% endblock %}
</body>
Я установил стиль для всех форм и прекрасно работает с использованием Bootstarp 3/4 , Для настройки я создал form_theme.html.twig и установки в config.yml
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'MyBundle:Form:form_theme.html.twig'
- 'MyBundle:Form:table_theme.html.twig'
MyBundle: Форма: form_theme.html.twig:
{%- block form_start -%}
{% spaceless %}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
{% set attr = attr|merge({'class': (attr.class|default('form-horizontal'))|trim }) %}
<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 -%}
{% endspaceless %}
{%- endblock form_start -%}
{% block form_row %}
{% spaceless %}
<div class="form-group row{{ errors|length > 0 ? ' has-error':'' }}">
{{ form_label(form) }}
<div class="col-10">
{{ form_widget(form) }}
{{ form_errors(form) }}
</div>
</div>
{% endspaceless %}
{% endblock form_row %}
{# Labels #}
{%- block form_label -%}
{% spaceless %}
{% if label is not same as(false) -%}
{% if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %}
{%- endif -%}
{% if required -%}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' col-sm-2 col-form-label')|trim }) %}
{% 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 -%}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</label>
{%- endif -%}
{% endspaceless %}
{%- endblock form_label -%}
{# Widgets #}
{%- block form_widget_simple -%}
{% spaceless %}
{%- set type = type|default('text') -%}
{% if type != 'file' %}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim }) %}
{% endif %}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{%- endblock form_widget_simple -%}
{%- block textarea_widget -%}
{% spaceless %}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim }) %}
<textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
{% endspaceless %}
{%- endblock textarea_widget -%}
{%- block choice_widget_collapsed -%}
{% spaceless %}
{%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%}
{% set required = false %}
{%- endif -%}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim }) %}
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
{%- if placeholder is not none -%}
<option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) }}</option>
{%- endif -%}
{%- if preferred_choices|length > 0 -%}
{% set options = preferred_choices %}
{{- block('choice_widget_options') -}}
{%- if choices|length > 0 and separator is not none -%}
<option disabled="disabled">{{ separator }}</option>
{%- endif -%}
{%- endif -%}
{%- set options = choices -%}
{{- block('choice_widget_options') -}}
</select>
{% endspaceless %}
{%- endblock choice_widget_collapsed -%}
{%- block choice_widget_expanded -%}
{% spaceless %}
{%- for child in form %}
<div class="checkbox">
<label>
{{- form_widget(child) -}}
{{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}
</label>
</div>
{% endfor -%}
{% endspaceless %}
{%- endblock choice_widget_expanded -%}
{% block form_errors %}
{% spaceless %}
{% for error in errors %}
<span class="help-block">{{ error.message }}</span>
{% endfor %}
{% endspaceless %}
{% endblock form_errors %}
{% block button_row %}
{% spaceless %}
<div class="form-group row">
<div class="offset-sm-2 col-sm-10">
{{ form_widget(form) }}
</div>
</div>
{% endspaceless %}
{% endblock button_row %}
{%- block button_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 -%}
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' btn')|trim }) %}
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</button>
{%- endblock button_widget -%}
{% block submit_widget %}
{% spaceless %}
{% set type = type|default('submit') %}
{% set attr = attr|merge({'class': (attr.class|default('btn btn-primary'))|trim }) %}
{{ block('button_widget') }}
{% endspaceless %}
{% endblock submit_widget %}
Я трей это сделать то же самое для таблицы, но в полях (поставщик \ symfony \ symfony \ src \ Symfony \ Bridge \ Twig \ Resources \ views \ Form):
- bootstrap_3_horizontal_layout.html.twig
- bootstrap_3_layout.html.twig
- form_div_layout.html.twig
- form_table_layout.html.twig
- foundation_5_layout.html.twig
Я не найти таблицы тегов для настройки: thead, cellpadding.
Как мне иметь одинаковый макет для всех таблиц в Symfony?
Это не решило всю проблему, но спасибо за предложение :-) – janek1
@JanNowak, что не работает? –
Я хочу изменить padding для записей и для тех же представлений Я не использую base.html.twig. На той же странице у меня есть более одной таблицы и текста – janek1