【问题标题】:symfony2/twig: How to simulate the old slots of symfony1 in symfony2?symfony2/twig:如何在 symfony2 中模拟 symfony1 的旧插槽?
【发布时间】:2012-07-12 14:01:03
【问题描述】:

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

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

并尝试在控制器中设置一个变量,但在 twig 中没有像 isset() 这样的东西...

有什么想法吗?

【问题讨论】:

    标签: symfony twig


    【解决方案1】:

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

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

    并在您的登录模板中重载它:

    {% block loginForm %}{% endblock %}
    

    【讨论】:

      【解决方案2】:

      定义了等价于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 %}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-16
        • 1970-01-01
        • 2013-12-31
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多