symfony2/twig: จะจำลองสล็อตเก่าของ symfony1 ใน symfony2 ได้อย่างไร

ฉันแค่ไม่ต้องการแสดงแบบฟอร์มเข้าสู่ระบบของเค้าโครงในหน้าเข้าสู่ระบบหลัก..

ฉันพยายามตั้งค่าตัวแปรในเทมเพลตลูกสำหรับเข้าสู่ระบบ ({% set layout_login = false %}) และตรวจสอบค่าของมันในเลย์เอาต์ แต่ฉันต้องตั้งค่าตัวแปรในเลย์เอาต์ด้วย ({% set layout_login = true %}) และมันจะจับค่าของตัวแปรที่ตั้งค่าไว้ในเลย์เอาต์เสมอ (จริง)....

และลองตั้งค่าตัวแปรในคอนโทรลเลอร์ด้วย แต่ไม่มีอะไรที่เหมือนกับ isset() ในทวิก...

มีความคิดอะไรบ้าง?


person ziiweb    schedule 12.07.2012    source แหล่งที่มา


คำตอบ (2)


ทำไมคุณไม่กำหนดบล็อกในเลย์เอาต์หลักของคุณล่ะ?

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

และโอเวอร์โหลดในเทมเพลตการเข้าสู่ระบบของคุณ:

{% block loginForm %}{% endblock %}
person Jakub Zalas    schedule 12.07.2012

เทียบเท่ากับ 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 %}
person ziiweb    schedule 12.07.2012