阻止javascript不起作用

时间:2017-08-02 11:01:29

标签: javascript symfony twig

我有这个带有materialize.ccs的base.html.twig

<!DOCTYPE html>
<html lang="en">

<!--================================================================================
    Item Name: Materialize - Material Design Admin Template
    Version: 3.1
    Author: GeeksLabs
    Author URL: http://www.themeforest.net/user/geekslabs
================================================================================ -->

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="msapplication-tap-highlight" content="no">
  <meta name="description" content="Materialize is a Material Design Admin Template,It's modern, responsive and based on Material Design by Google. ">
  <meta name="keywords" content="materialize, admin template, dashboard template, flat admin template, responsive admin template,">
  <title>{% block title %}Login Page | Materialize - Material Design Admin Template{% endblock %}</title>


  <!-- Favicons-->
  <link rel="icon" href="images/favicon/favicon-32x32.png" sizes="32x32">
  <!-- Favicons-->
  <link rel="apple-touch-icon-precomposed" href="images/favicon/apple-touch-icon-152x152.png">
  <!-- For iPhone -->
  <meta name="msapplication-TileColor" content="#00bcd4">
  <meta name="msapplication-TileImage" content="images/favicon/mstile-144x144.png">
  <!-- For Windows Phone -->

 {% block stylesheets %}
  <!-- CORE CSS-->

  <link href="{{asset('css/materialize.css')}}" type="text/css" rel="stylesheet" media="screen,projection">
  <link href="{{asset('css/style.css')}}" type="text/css" rel="stylesheet" media="screen,projection">
    <!-- Custome CSS-->    
    <link href="{{asset('css/custom/custom.css')}}" type="text/css" rel="stylesheet" media="screen,projection">
  <link href="{{asset('css/layouts/page-center.css')}}" type="text/css" rel="stylesheet" media="screen,projection">

  <!-- INCLUDED PLUGIN CSS ON THIS PAGE -->
  <link href="{{asset('js/plugins/prism/prism.css')}}" type="text/css" rel="stylesheet" media="screen,projection">
  <link href="{{asset('js/plugins/perfect-scrollbar/perfect-scrollbar.css')}}" type="text/css" rel="stylesheet" media="screen,projection">

  {% endblock %}

</head>

<body class="cyan">
 {% block body %}

 {% endblock %}

{% block javascript %}
  <!-- ================================================
    Scripts
    ================================================ -->

  <!-- jQuery Library -->
  <script type="text/javascript" src="{{asset('js/plugins/jquery-1.11.2.min.js')}}"></script>
  <!--materialize js-->
  <script type="text/javascript" src="{{asset('js/materialize.js')}}"></script>
  <!--prism-->
  <script type="text/javascript" src="{{asset('js/plugins/prism/prism.js')}}"></script>
  <!--scrollbar-->
  <script type="text/javascript" src="{{asset('js/plugins/perfect-scrollbar/perfect-scrollbar.min.js')}}"></script>

      <!--plugins.js - Some Specific JS codes for Plugin Settings-->
    <script type="text/javascript" src="{{asset('js/plugins.js')}}"></script>
    <!--custom-script.js - Add your own theme custom JS-->
    <script type="text/javascript" src="{{asset('js/custom-script.js')}}"></script>

    <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
    <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>


{% endblock %}
</body>

</html>

如果我尝试在另一个文件中扩展javascript它不起作用

{% extends 'base.html.twig' %}

{% block body %}  


{% endblock %}

{% block javascripts %}

      {{parent()}}
        <script src="{{ asset('js/xxxxx.js') }}"></script>

{% endblock %}

这个街区看不到.. 我在其他项目中使用了这个和其他模板一起工作...... 如果我更改(file.js的名称)控制台浏览器没有看到任何错误,所以我认为没有正确添加到twig文件。 可以帮帮我??

2 个答案:

答案 0 :(得分:2)

您的base.html.twig中有一个拼写错误,您将块javascript命名为没有“s”;)

答案 1 :(得分:1)

在第二个文件中使用{%block javascripts%} {%block javascript%}