0

Hi Stackoverflow people.

Im trying to use a javascript graph in a test twig view. This is the view:

    <h1>test</h1>
{% javascripts '@AcmeFooBundle/Resources/public/js/*' %}
  <script src="{{ asset_url }}"  type="text/javascript">
  window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer", {

  title:{
    text: "Fruits"              
  },
  data: [//array of dataSeries              
    { //dataSeries object

     /*** Change type "column" to "bar", "area", "line" or "pie"***/
     type: "column",
     dataPoints: [
     { label: "banana", y: 18 },
     { label: "orange", y: 29 },
     { label: "apple", y: 40 },                                    
     { label: "mango", y: 34 },
     { label: "grape", y: 24 }
     ]
   }
   ]
 });

chart.render();
  }


     </script>
      <script type="text/javascript" src="{{ asset_url }}"></script>
      {% endjavascripts %}

      <body>
      <div id="chartContainer" style="height: 300px; width: 100%;">
      </div>
    </body>

So the problem is that the javascript library is not installed because it returns to me this error message:

An exception has been thrown during the compilation of a template ("You must add PreditBundle to the assetic.bundle config to use the {% javascripts %} tag in PreditBundle:Default:test.html.twig.") in "PreditBundle:Default:test.html.twig".

Things I've tryed:

-Follow step by step the page "how to use assetic for asset management -Use the console comands : assets:install and assetic:dump

Thanks for your answers

2 Answers 2

1

You have to add your bundle in config.yml.

assetic:
    bundle: [ PreditBundle ]
Sign up to request clarification or add additional context in comments.

Comments

1

You defined the scr attribute for a script element and than use inline javascript code? Do either:

<script src="..."></script>

or:

<script> alert(123); </script>

Also the {% javascript %} block of twig is for rendering multiple javascript assets in one step. Not for inline and remote javascript files. Use it like this:

your-template.html.twig:

{% javascript '@AcmeFooBundle/Resources/public/js/*' %}
<script src="{{ asset_url }}"  type="text/javascript">
{% javascript %}
<script>

    window.onload = function () {
    // ...

</script>

Also you need to add your bundle in config.yml as @oumlaote already stated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.