将AdminLTE模板集成到Symfony时,表单无法正确显示

时间:2016-08-19 10:32:40

标签: twitter-bootstrap-3 twig symfony adminlte

我为我的实体使用了CRUD生成器,然后我集成了一个模板AdminLTE;有用;现在我尝试设置我的twig文件的显示我从new.html.twig文件(表单)开始我希望它遵循基本模板的布局

new.html.twig

{% extends 'base.html.twig' %}
{% block body  %}
    <h1>User creation</h1>

    {{ form_start(form) }}
        {{ form_widget(form) }}
        <input type="submit" value="Create" />
    {{ form_end(form) }}

    <ul>
        <li>
            <a href="{{ path('user_index') }}">Back to the list</a>
        </li>
    </ul>   
{% endblock %}

index.html.twig

{% extends 'base.html.twig' %}
{% block body  %}    
    <h1>User list</h1>

    <table>
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Lastname</th>
                <th>Gender</th>
                <th>Birthday</th>
                <th>Birthplace</th>
                <th>Email</th>
                <th>Phonenumber</th>
                <th>Grade</th>
                <th>Profile</th>
                <th>Documentid</th>
                <th>Photoid</th>
                <th>Directeur</th>
                <th>Codirecteur</th>
                <th>Effectue</th>
                <th>Mediaid</th>
                <th>Created</th>
                <th>Updated</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        {% for user in users %}
            <tr>
                <td><a href="{{ path('user_show', { 'id': user.id }) }}">{{ user.id }}</a></td>
                <td>{{  user.name }}</td>
                <td>{{  user.lastName }}</td>
                <td>{{ user.gender }}</td>
                <td>{% if user.birthday %}{{ user.birthday|date('Y-m-d') }}{% endif %}</td>
                <td>{{ user.birthPlace }}</td>
                <td>{{ user.email }}</td>
                <td>{{ user.phoneNumber }}</td>
                <td>{{ user.grade }}</td>
                <td>{{ user.profile }}</td>
                <td>{{ user.documentId }}</td>
                <td>{{ user.photoId }}</td>
                <td>{% if user.directeur %}Yes{% else %}No{% endif %}</td>
                <td>{% if user.coDirecteur %}Yes{% else %}No{% endif %}</td>
                <td>{% if user.effectue %}Yes{% else %}No{% endif %}</td>
                <td>{{ user.mediaId }}</td>
                <td>{% if user.created %}{{ user.created|date('Y-m-d H:i:s') }}{% endif %}</td>
                <td>{% if user.updated %}{{ user.updated|date('Y-m-d H:i:s') }}{% endif %}</td>
                <td>
                    <ul>
                        <li>
                            <a href="{{ path('user_show', { 'id': user.id }) }}">show</a>
                        </li>
                        <li>
                            <a href="{{ path('user_edit', { 'id': user.id }) }}">edit</a>
                        </li>
                    </ul>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <ul>
        <li>
            <a href="{{ path('user_new') }}">Create a new entry</a>
        </li>
    </ul>
{% endblock %}

config.yml

#Twig Configuration twig: 
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes: - user:new.html.twig

在接触config.yml之前,我附上了display:

enter image description here

1 个答案:

答案 0 :(得分:0)

你的问题很模糊,但我认为我看到了这个问题。

您希望将AdminLTE模板集成到Symfony3中,您已经使用所需的HTML&amp;更新了base.html.twig(所有其他模板将扩展)。 CSS,但您的表单元素显示不正确(查看提供的屏幕截图)。

默认情况下,我们可以使用以下方法之一指示Symfony使用引导样式呈现所有表单。

适用范围广

这将使用引导类渲染所有树枝形式

更新您的app/config/config.yml以包含以下内容。

# app/config/config.yml
twig:
    form:
        # All forms will use the `vertical` bootstrap form layout
        resources: ['bootstrap_3_layout.html.twig']

        # All forms will use the `horizontal` layout
        # resources: ['bootstrap_3_horizontal_layout.html.twig']

表格特定

我们可以使用以下方式将样式应用于单枝形式 请注意form_theme标记,该标记接受form和表单主题。

{% extends 'base.html.twig' %}
{% block body  %}
    <h1>User creation form</h1>

    {# {% form_theme form 'bootstrap_3_horizontal_layout.html.twig' %} #}

    {% form_theme form 'bootstrap_3_layout.html.twig' %}
    {{ form_start(form) }}
        {{ form_widget(form) }}
        <input type="submit" value="Create" />
    {{ form_end(form) }}
{% endblock %}

AdminLTE Symfony Bootstrap Form Integration

  

Symfony文档更详细地介绍了表单自定义。

     
相关问题