2017-10-30 4 views
0

aufrufen Nach der Aktualisierung "twig/twig" zu "v2.4.4" Ich habe einen Fehler beim Aufruf der Makrofunktion.Twig unmöglich, eine Methode auf einer Zeichenfolge Variable

Impossible to invoke a method ("widget_prototype") on a string variable (":ERP/timesheets:_form_part.html.twig"). 

Mein Makro:

{% macro widget_prototype(widget, remove_text) %} 
{% if widget.vars.prototype is defined %} 
    {% set form = widget.vars.prototype %} 
    {% set name = widget.vars.prototype.vars.name %} 
{% else %} 
    {% set form = widget %} 
    {% set name = widget.vars.full_name %} 
{% endif %} 

Aufruf Makro Teil:

{% include ':ERP/timesheets:_data_content_supply_from_widget.html.twig' with {form:form, name:name} %} 

{% endmacro %} 

      <div id="post_supplies" 
      data-prototype="{{ _self.widget_prototype(form.supplies, 'remove'|trans({}, 'common'))|escape }}" 
      style="margin-bottom: 5px"> 
      {% for widget in form.supplies.children %} 
       {{ _self.widget_prototype(widget, 'remove'|trans({}, 'common')) }} 
      {% endfor %} 
     </div> 

Wie richtig Makro nennen? Versuchte ohne _self Aufruf und ich habe den Fehler: Unknown "widget_prototype" function.

Antwort

1

Sie müssen das Makro importieren, ist es nicht

{% import "my_macro.twig" as my_macro %} 
{{ my_macro.function(arg1) }} 
Verwandte Themen