我遇到了标题中建议的问题,用树枝。准确的错误如下:
Attempted to call an undefined method named "getpreReady" of class "__TwigTemplate_9583a7109672ac89ad8f73f6abf919dbeb71998598a2a1a4613d3457606a7304".
使用宏时会发生这种情况。这是我的呼叫模板:

{% extends 'MRPlatformBundle:Full/AbstractForm:form.html.twig' %}

{% set isSenior = (type=='logeur(se)') ? true : false %}

{%use 'MRPlatformBundle:Common/Person/addForm:addFormBlocks.html.twig'%}
{%import 'MRPlatformBundle:Common/Person/addForm:addFormMacros.html.twig' as common %}

{%block CSSexterne%}
    {{parent()}}
    {{common.CSSexterne()}}
{%endblock%}

{%block JSexterne%}
    {{parent()}}
    {{common.JSexterne()}}
{%endblock%}

{%block preReady%}
    {{parent()}}
    {{common.preReady()}}
{%endblock%}

以下是宏文件的行:
{% macro CSSexterne() %}
  <link rel='stylesheet' type='text/css' href="{{ asset('CSS-JS/TimePicki-master/css/timepicki.css') }}"/>
  <link href="{{asset('CSS-JS/jQueryFiler/css/jquery.filer.css')}}" type="text/css" rel="stylesheet" />
  <link href="{{asset('CSS-JS/jQueryFiler/css/themes/jquery.filer-dragdropbox-theme.css')}}" type="text/css" rel="stylesheet" />
  <link href="{{asset('CSS-JS/slim/slim/slim.min.css')}}" rel="stylesheet">
{% endmacro %}

{% macro JSexterne() %}
   <script src="{{asset('CSS-JS/TimePicki-master/js/timepicki.js')}}"></script>
   <script src="{{asset('CSS-JS/jQueryFiler/js/jquery.filer.min.js')}}"></script>
   <script src="{{asset('CSS-JS/slim/slim/slim.kickstart.js')}}"></script>
{% endmacro %}

{% macro preReady() %}

var placeSearch, autocomplete, target;
var componentForm = {
  street_number: 'short_name',
  route: 'long_name',
  locality: 'long_name',
  administrative_area_level_1: 'short_name',
  country: 'long_name',
  postal_code: 'short_name'
};


[...]

$(".lat").val(place.geometry.location.lat());
$(".lng").val(place.geometry.location.lng());
}
{% endmacro %}

我错过了什么?
非常感谢,提前!

最佳答案

您需要在要使用宏文件的每个文件中导入宏文件。模板的文件是否已经导入并不重要,您仍然需要手动导入它。
在文件顶部添加:

{% import "your_macro_file.ext" as common %}

这样您可以使用:
common.CSSexterne()

关于php - 尝试调用名为“getpreReady”的未定义方法(Twig和Symfony3),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38777504/

10-11 12:34