symfony2 / twig:如何在symfony2中模拟symfony1的旧槽?

时间:2012-07-12 14:01:03

标签: symfony twig

我只是不想在主登录页面中显示布局的登录表单。

我尝试在登录子模板({% set layout_login = false %})中设置一个变量并检查其在布局中的值,但我还需要在布局中设置变量({% set layout_login = true %}),然后总是捕获布局中设置的变量的值(true)....

并尝试在控制器中设置变量,但在树枝上没有isset()之类的东西...

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

为什么不在主布局中定义一个块?

{% block loginForm %}
    <form />
{% endblock %}

并在登录模板中重载:

{% block loginForm %}{% endblock %}

答案 1 :(得分:0)

定义了与isset()的等价物。

我写的是这样的:

{% if layout_login is not defined %}

    {% if error %}
        <div>{{ error|trans({}, 'FOSUserBundle') }}</div>
    {% endif %}

    <form action="{{ path("fos_user_security_check") }}" method="post">
        <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

        <label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>
        <input type="text" id="username" name="_username" value="{{ last_username }}" />

        <label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>
        <input type="password" id="password" name="_password" />

        <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
        <label for="remember_me">{{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}</label>

        <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
    </form>

{% endif %}