试图调用名为“getpreReady”的未定义方法(Twig& Symfony3)

时间:2016-08-04 21:13:54

标签: php templates twig symfony

我使用Twig遇到了标题中建议的问题。确切的错误如下: 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 %}

我错过了什么点?

非常感谢,提前!

1 个答案:

答案 0 :(得分:1)

您需要在要使用它的每个文件中导入宏文件。如果模板的文件已经导入它并不重要,您仍然需要手动导入它。

在文件顶部添加:

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

这样你可以使用:

common.CSSexterne()