简体   繁体   English

在树枝中传递参数(从模板到另一个模板)

[英]Passing parameters in twig (from template to another template)

Parent:
       {% block row -%}{% endblock %}    
Child:
      {% block row -%}
      {{ parent() }}
      {% set boy = {
          'name': 'foo',
          'age': 12,
        }
      %}
      {% endblock %}

My question is, how do I pass the boy object to the Parent (without losing its value)? 我的问题是,如何将男孩对象传递给父对象(而不丢失其值)?

I don't think its a good idea to put any business logic inside your template. 我认为在模板中放置任何业务逻辑不是一个好主意。 If you need the boy object in your parent theme, you should define it in your controller instead and pass it to the template. 如果在父主题中需要男孩对象,则应在控制器中定义它,并将其传递给模板。 Both the parent and child templates can access that object. 父模板和子模板都可以访问该对象。

You can do something like: 您可以执行以下操作:

{% extends 'ProjectCommonBundle:Email:base.html.twig' %}

{# set the vars you need on your base layout #}
{% set organization = organization %}
{% set emailTo = emailTo %}

{% block body %}

{% endblock %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM